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.

7
  • Is the iframe in a different domain from the parent page? Commented Apr 13, 2011 at 15:52
  • In the "Save and close" callback, if you do a console.log($( "#iframe").contents().find("#contentform").length); what gets logged? Commented Apr 13, 2011 at 16:22
  • Could you show us the HTML of the form? How do you know that the form submission isn't working? Commented Apr 13, 2011 at 16:38
  • <form name="contentform" id="contentform" action="myfile2.asp?pid=<%=pid%>&cid=<%=cid%>&update=1" method="post" enctype="multipart/form-data"> <textarea id="myTextArea" name="myTextArea" style="height:250px;"> <%=sContent%> </textarea> <input type="hidden" name="eid" id="eid" value="<%=eid%>"> <input type="hidden" name="delimg" id="delimg" value=""> </form> Commented Apr 13, 2011 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 Commented Apr 13, 2011 at 16:48

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.