两个表单一个提交按钮,一个iframe

时间:2012-11-06 20:05:51

标签: javascript forms submit

我有一个包含两个字段的iframe和一个包含多个字段的表单。我想要做的是点击提交'在iframe上,当用户点击非iframe表单上的提交时,以便提交第一个表单,然后提交第二个表单。这可能吗?感谢

--- 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

1 个答案:

答案 0 :(得分:2)

是的,这是可能的。

<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>