我有2個表格。當我提交frm1時,我有一些檢查選項並使用變量checkedValues來存儲它。循環並提交表格jquery
我在每個選中的選項中循環,將值更改爲frm2,提交併在3秒後打開彈出窗口。但它不適用於提交表單2和setTimeout函數。
有沒有人有任何想法來解決這個問題?
<form action="" method="post" name='frm1'>
<input type="checkbox" name="1" id="1" value="1" class="checkbox">
<input type="checkbox" name="2" id="2" value="1" class="checkbox">
<input type="checkbox" name="3" id="3" value="0" class="checkbox">
<input type="checkbox" name="4" id="4" value="0" class="checkbox">
<input type="submit" value='add'>
</form>
<form action='http://example.com' method='post' name='frm2' target="_blank">
<input type="text" name="fname" class="form-control" value=''>
<input type="text" name="fvalue"class="form-control" value=''>
</form>
<script>
$('#add').click(function(){
var store= <?php echo json_encode($store)?>;
var checkedValues = $('input:checkbox:checked').map(function() {
return this.id;
}).get();
$.each(checkedValues, function(index,val) {
document.frm2.fname.value = store[val]['name'];
document.frm2.fvalue.value = store[val]['value'];
document.frm2.submit(); // not working
setTimeout(function() { // not working
window.open("http://example.com/client, "_blank"), 3000);
});
});
});
</script>
表單沒有值。輸入具有值。你想在這裏做什麼? 'document.frm2.value.value = store [val] ['value'];' –
此外,爲什麼不使用'console.log()'來查看'$'的前2個賦值.each()'迭代?檢查目標(以驗證它們是您打算定位的目標)並分配新值。 –
您的表單一提交,您就會失去控制權。在提交表單之前打開彈出窗口。 – dave