Kristian
Kristian

Reputation: 1388

two forms one submit button, one iframe

I have an iframe that contains two fields and a form that contains multiple fields. What I want to do is click 'submit' on iframe when the user clicks submit on the non iframe form so that first form gets submitted and then the second form is submitted. Is this possible? Thanks

--- IFRAME ---
[Input 1]
[Input 2]
[Hidden Submit]
--- IFRAME ---

[Input 3]
[Input 4]
[Submit] <-- user is gonna click this, then iframe form and this form gets submitted

Upvotes: 0

Views: 1014

Answers (1)

Min Yang
Min Yang

Reputation: 88

yes, that's possible.

<iframe name="myframe" onload="submitForm()"></frame>

<form action="" method="post" onsubmit="return subIframe()" id="form1">
<input type="text" name="input1" value=""/>
<input type="text" name="input2" value=""/>
<input type="submit" value="submit">
</form>

<script>
var flag=1;
/*submit the iframe form fist*/
function subIframe(){
    /*submit the form in iframe here*/
    if(flat==1){
       myframe.document.getElementById("myform").submit();
       flat=0;
       return false;
    }else{
       return true;
    }

}


/*after the iframe form been submited, submit the form in the current page*/
function submitForm(){
 document.getElementById("form1").submit();
}
</script>                                                  

Upvotes: 2

Related Questions