Click here to Skip to main content
15,901,853 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
code $(this._element).append('<input type="button" value="close" onclick="'+obj+'.quit('+obj._roomid+');"/>');
is not working .how can i call function quit when pressing button close in below code
C#
Box.prototype = {
    get_title: function () {
        return this._title;
    },
    set_title: function (val) {
        this._title = val;
    },
    get_roomid: function () {
        return this._roomid;
    },
    set_roomid: function (val) {
        this._roomid = val;
    },
    open: function (RoomId, RoomName) {
        if ($.inArray(RoomId, lockBox) == -1) {
            this._roomid = RoomId;
            this._title = RoomName;
          
            this._element = document.createElement("DIV");

            this._element.style.display = "none";
            this._iframe = document.createElement("IFRAME");
            this._iframe.src = "chatbox.aspx?i=" + RoomId;
            this._iframe.style.width = "800px";
            this._iframe.frameBorder = 0;
            this._iframe.style.height = "360px";
            this._iframe.scrolling = "no";
            this._element.appendChild(this._iframe);

            document.body.appendChild(this._element);
           
            $(this._element).append('<input value="close"  type="button" onclick="'+obj+'.quit('+obj._roomid+');"/>');
            var obj = this;
           
             $(this._element).show();
            lockBox.push(RoomId);
            $addHandler(window, "unload", function () {
                obj.quit(obj._roomid);
            });
            $("#_cu_" + RoomId).html(Number($("#_cu_" + RoomId).html()) + 1);
        }
        else {
            ShowMessageBox("Exception", "You have joined the chat room");
        }
    },
    quit: function (roomid) {
        ShowMessageBox("Leave Chat Room", "Please waiting...");
        csaspnetajaxwebchat.transition.LeaveChatRoom(roomid, function () {
            lockBox = $.map(lockBox, function (n) {
                return n != roomid ? n : null;
            });

            $("#_cu_" + roomid).html(Number($("#_cu_" + roomid).html()) - 1);

            CloseMessageBox();
        });

    },
    test: function (roomid) {
        alert(roomid);
    }
}
Posted
Updated 19-Sep-13 19:50pm
v2

HTML markup
HTML
<div id="Message_Box_Id">
     <div id="Close_button_Id">
          Close button content
     </div>
     Other stuffs for message box.
  </div>

Java script code to close message box div on click of close
JavaScript
$("#Close_button_Id").click(function(){
   $("#Message_Box_Id").hide();
});
 
Share this answer
 
v2
Comments
shyam0302 20-Sep-13 6:38am    
plz read question before answering . i want to bind function inside object Box . button element created using CreateElement
 
Share this answer
 
v3
Comments
shyam0302 20-Sep-13 5:01am    
plz read question before answering . i want to bind function inside object Box . button element created using CreateElement
Hi Shyam,

You can modify the following code -
JavaScript
$(this._element).append('<input value="close" type="button"  önclick="'+obj+'.quit('+obj._roomid+');" />');
var obj = this;
$(this._element).show();

And, rewrite as -
JavaScript
var obj = this;
var $tempCloseButton = $('<input value="close" type="button" />'); 
//bind click event to the elemebt
$tempCloseButton.on('click', function(e){
obj.quit(obj._roomid)
e.preventDefault();
});
//append the element
$(this._element).append($tempCloseButton);
$(this._element).show();


I hope this will help.
Thanks
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900