2012-11-06 2 views
0

두 필드가 들어있는 iframe과 여러 필드가 들어있는 양식이 있습니다. 내가 원하는 것은 iframe에서 'submit'을 클릭하면 사용자가 비 iframe 양식에서 submit을 클릭하면 첫 번째 양식이 제출되고 두 번째 양식이 제출됩니다. 이것이 가능한가? 감사합니다.두 개의 양식을 하나의 제출 버튼, 하나의 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

동일한 도메인 이름의 iframe입니까? – Ibu

+0

아니요 iframe이 다른 도메인입니다 – Kristian

+1

[동일 원본 정책] (http://javascript.info/tutorial/same-origin-security-policy) – Ibu

답변

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>             
관련 문제