-1

I am using jquery dialog for for user to enter comments and than i had add and cancel button within jquery dialog. I have a logic like when they hit add i need to insert text in database and refresh only iframe within the whole html page. Everything works perfect. But when iframe refresh than it keep the old dialog in dom event. so when i click second time on than it appear with expected screen. But i am not sure why on first click it will keep the old jquery dialog.

I am using this code :;

   $("#dialog-confirm").dialog({
        resizable: false,
        height: 200,
        modal: true,
        autoOpen: false,
       buttons: [
        {
            id: "add_btn",
            text: "Add",
           disabled: true,
            click: function () {
           // logic of adding text in db goes here.
             $(this).dialog("close");
            }
        },
        {
            id: "cancel_btn",
            text: "Cancel",
            click: function () {
            $(this).dialog("close");
            }
        }
        ]
    });

Thanks in advance.

Selvakumar Arumugam
  • 79,297
  • 15
  • 120
  • 134
ravi patel
  • 31
  • 4

2 Answers2

0
function resetForm($form) {
    $form.find('input:text, input:password, input:file, select, textarea').val('');
    $form.find('input:radio, input:checkbox')
         .removeAttr('checked').removeAttr('selected');
}

and call resetForm($('#myform')); // by id

OR

jQuery.fn.reset = function () {
  $(this).each (function() { this.reset(); });
}

call $("#FormID").reset();

OR

$('#FormID').each (function(){
  this.reset();
});

If your using form above code will be correct but not in case that will be use like this

$("#clear").click(function(){
    $("input[type='text']").val(""); 
});
Sender
  • 6,660
  • 12
  • 47
  • 66
  • Thanks dude.. I will try.. U mean #fromid to "#dialog-confirm" with respect to my code? is that right? – ravi patel Sep 10 '12 at 16:03
  • where you reset form call just note down. – Sender Sep 10 '12 at 16:22
  • Ok i solved it..i used this code $('#dialog-confirm').dialog('destroy').remove(). So it basically destory every event asscoiated with that dialog box from DOM.it work out..anyways thanks a lot guys!! – ravi patel Sep 10 '12 at 16:34
0

Seems your iframe is getting cached, Take a look into this,

Preventing iframe caching in browser

Also post the browser and version you are using it for testing.

Community
  • 1
  • 1
Vivek S
  • 5,384
  • 8
  • 51
  • 72
  • Thanks.I am using ie7. I dont have a control over the iframe.I mean i am working on api. so i just have to pass the id in javascript and our inner framwork will refresh iframe for me..so technically i cant change anything in framework. I need to clear the event.This is my last option. – ravi patel Sep 10 '12 at 16:08