<form action="" method="post">
<select name="select1">
<option value="value1">Value one</option>
<option value="value2">Value two</option>
</select>
<input type="submit" name="submit" value="Go"/>
</form>
Onsubmit,我需要在提交时打印Value one
。所有帖子都使用$_POST['select1']
来获取值。但它只会给value1
答案 0 :(得分:1)
试试这个
function changeValue(){
var e = document.getElementById("select1");
var strUser = e.options[e.selectedIndex].text;
document.getElementById("submit").value = strUser;
}
&#13;
<form action="" method="post">
<select name="select1" id="select1">
<option value="value1">Value one</option>
<option value="value2">Value two</option>
</select>
<input type="submit" name="submit" id="submit" value="Go" onclick="changeValue();"/>
</form>
&#13;