我在单页中有两种形式。有一种方法可以在提交form2之前从form1获取所选值。所以我可以在一个表中插入两个值(form1中的选定值和form2中的输入框值)作为单行。需要帮助
HTML:
<form name="form1" id="form1" method="POST" action="">
<table>
<tr>
<td><select name="type">
<option value="">Select Type</option>
<option value="val1" selected="selected">val1</option>
<option value="val2">val2</option>
</select></td>
</tr>
</table>
</form>
<form name="form2" id="form2" method="POST" action="">
<table>
<tr>
<td><input type="text" id="test1"></td>
<td><input type="submit" name="go" value="go" /></td>
</tr>
</table>
</form>
答案 0 :(得分:1)
1. just use a hidden field in form two and when ever the select box changes assign the changedvalue to the hidden field
$('#selectbox').on('change',function() {
$('#hiddenfield').val($('#selectbox').val());//HIDDEN FIELD PLACED IN FORM 2
});
by this method you could get the form 1 value to form 2 submit.
你可以使用这个小提琴:http://jsfiddle.net/hoja/jw3y9ky7/
答案 1 :(得分:0)
jQuery('#form2').submit(function(){
var valueSelected = jQuery("select[name='type']").val();
//Do what you want
});
您可以使用valueSelected变量来执行您想要的操作。