1

I'm using jquery to open a dialog containing an iframe (don't ask!). I want to submit the form in the iframe on closing the dialog but it isn't working.

I'm probably making a simple error (I'm quite new to jquery) but this problem has been driving me round the bend.

Here is my code:

    $(function() {

    $( "#iframe" ).dialog({
        modal: true,
        autoOpen: false,
        height: 500,
        width: 700,
        buttons: {
            "Save and close": function() {
                $( "#iframe").contents().find("#contentform").submit();
                $( "#iframe" ).dialog( "close" );
            },
            Cancel: function() {
                $( "#iframe" ).dialog( "close" );
            }
        }
    });

    $( "#openProfile" ).click(function() {
        $( "#iframe" ).dialog( "open" );
        $('#iframe').attr('src','file.asp');
        return false;
    });     
});

However, if I do this instead of submitting the form:

"Save and close": function() {
var myformvalue = $( "#iframe").contents().find("#formfield").val();
alert(myformvalue);
$( "#iframe" ).dialog( "close" );
}

...it returns the correct value so I know it is recognising my form and its values.

Thanks in advance for your help.

bob808
  • 11
  • 1
  • 2
  • Is the `iframe` in a different domain from the parent page? – Matt Ball Apr 13 '11 at 15:52
  • In the `"Save and close"` callback, if you do a `console.log($( "#iframe").contents().find("#contentform").length);` what gets logged? – Matt Ball Apr 13 '11 at 16:22
  • Could you show us the HTML of the form? How do you know that the form submission isn't working? – Matt Ball Apr 13 '11 at 16:38
  • `
    `
    – bob808 Apr 13 '11 at 16:45
  • I have response.write "stop" response.end at the top of myfile2.asp but it doesn't get that far, the dialog just closes. The form submits fine when it isn't in the iframe. The iframe is unfortunately needed due to it being a legacy application using a text editor which doesn't work in conjunction with jQuery – bob808 Apr 13 '11 at 16:48
  • Is that because jQuery and the text editor both use `$`? You can work around that using [`jQuery.noConflict()`](http://api.jquery.com/jquery.noconflict). – Matt Ball Apr 13 '11 at 16:54
  • Your comment got me thinking and I decided to change text editors. All working now. Many thanks for taking the time to comment on my post. – bob808 Apr 14 '11 at 14:08

1 Answers1

0

I think you are running up against the jQuery V1.10(/9?) issue where they changed it so that the dialog container is moved out of the DOM, so you don't end up getting postbacks from the page in the iFrame. Reference this: https://stackoverflow.com/a/24663205/3334255 and An ASP.NET button click event is not firing

Community
  • 1
  • 1