各位高手好,我现在有这么一个东西<script>
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name).value;
txt_box.value=field.innerHTML;
}
</script>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select><input type="text" name="txt" id="txt" />
我想要的就是当我选择aaa后,在输入框txt中显示123456789,而如果选择了bbb,就显示abcdefg,以此类推.可是现在我选择后写入的都是undefined,不知何解?
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name).value;
txt_box.value=field.innerHTML;
}
</script>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select><input type="text" name="txt" id="txt" />
我想要的就是当我选择aaa后,在输入框txt中显示123456789,而如果选择了bbb,就显示abcdefg,以此类推.可是现在我选择后写入的都是undefined,不知何解?
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name).options[0].value;//这里要用选择option
txt_box.value=field;
}
</script>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select><input type="text" name="txt" id="txt" />
<script>
function getValue(name){
var txt_box=document.getElementById('txt');
var field=document.getElementById(name);txt_box.value=field.value;
}
</script></head><body>
<select id="select" name="select" onchange="getValue('select'); return false;">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select><input type="text" name="txt" id="txt" />
</body></html>
把value去掉就可以了
<script>
function getValue(value){
var txt_box=document.getElementById('txt');
txt_box.value=value;
}
</script>
<select id="select" name="select" onchange="getValue(this.value)">
<option value="123456789">aaa</option>
<option value="abcdefg">bbb</option>
<option value="123abc">ccc</option>
</select><input type="text" name="txt" id="txt" />