简体   繁体   中英

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

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>                                                  

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM