根据选择的选项值输入输入值 [英] Form input value based on option value selected
本文介绍了根据选择的选项值输入输入值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
以下表格
for the following form
<form action ='search.php' method = 'post'>
<select name="filter">
<option id="A" value="A">A</option>
<option id="B" value="B">B</option>
</select>
<input type ='text' name="key" id ="field" value ="something that changes based on what option is selected" />
<input type ='submit' value = 'Search' />
</form>
如何根据 A
或 B
是否被选中?我认为它必须在JavaScript中完成。我已经在这里和那里使用jQuery,所以可以根据它提出建议。
How do i make the value of the input field change based on whether A
or B
is selected? I assume it has to be done in javascript. I have used jquery here and there so it is ok to make suggestions based on it. Thanks alot!
推荐答案
您可以试试这个
<script type="text/javascript">
function changeValue(){
var option=document.getElementById('filter').value;
if(option=="A"){
document.getElementById('field').value="A Selected";
}
else if(option=="B"){
document.getElementById('field').value="B Selected";
}
}
</script>
<form action ='search.php' method = 'post'>
<select name="filter" id="filter" onchange="changeValue();">
<option id="A" value="A">A</option>
<option id="B" value="B">B</option>
</select>
<input type ='text' name="key" id ="field" value ="something that changes based on what option is selected" />
<input type ='submit' value = 'Search' />
</form>
这篇关于根据选择的选项值输入输入值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文