我尝试根据复选框的状态将多个表单提交到不同的位置。javascript 应该检查复选框并提交表单,但我无法让它工作。
<script type="text/javascript" charset="utf-8">
function checkSubmit() {
var frm1 = document.getElementById("optin1");
var frm2 = document.getElementById("optin2");
var frm3 = document.getElementById("optin3");
var chkbox1 = document.getElementById("c1");
var chkbox2 = document.getElementById("c2");
var chkbox3 = document.getElementById("c3");
if (chkbox1.checked === true) {
frm1.submit();
}
else // it is not checked, dont submit form
{
return false;
}
if (chkbox2.checked === true) {
frm2.submit();
}
else // it is not checked, dont submit form
{
return false;
}
if (chkbox3.checked === true) {
frm3.submit();
}
else // it is not checked, dont submit form
{
return false;
}
setTimeout(function() {
window.location = 'http://url.com/index.php';
}, 1350);
}
</script>
这里的html表单:
<form id="optin1" name="f1" method="post" action="file1.php" target="iframe1">
<input type="checkbox" id="c1" name="cc" value="" checked="checked">
<label for="c1"><span></span><strong>YES, I'd love to join!</strong></label>
<input name="email" type="hidden" value="<?=$_GET[email];?>"></form>
<form id="optin2" name="f2" method="post" action="file2.php" target="iframe2">
<input type="checkbox" id="c2" name="cc" value="" checked="checked">
<label for="c2"><span></span><strong>YES, I'd love to join!</strong></label>
<input name="email" type="hidden" value="<?=$_GET[email];?>">
<input name="name" type="hidden" value="Newsletter"></form>
<form id="optin3" name="f3" method="post" action="http://www.url.com" target="iframe3">
<input type="checkbox" id="c3" name="cc" value="" checked="checked">
<label for="c3"><span></span><strong>YES, I"d love to join!</strong></label>
<input id="txtEmail1" class="field" name="txtEmail1" value="<?=$_GET[email];?>" type="hidden">
<input type="hidden" value="18" name="webID">
<input type="hidden" value="20" name="usd">
<input type="hidden" value="25" name="lsvalue">
<input type="hidden" value="http://url.com/thanks" name="thanxurl">
<input type="hidden" value="http://url.com/confirm" name="confirmationurl"></form>
<form name="Submit">
<input name="btn1" type="image" onClick="checkSubmit()" src="images.jpg" align="left" />
</form>
<iframe name="iframe1" style="display:none"></iframe>
<iframe name="iframe2" style="display:none"></iframe>
<iframe name="iframe3" style="display:none"></iframe>
提交表单时,仅提交第一个表单。怎么了?