当我使用split()时,textfield值为空,从我需要的下拉文本字段的值是例如15。 请告诉我哪里出错了.. 感谢,
这是代码:
<select name="cmbitems" id="cmbitems">
<option value="price1:15">blue</option>
<option value="price2:20">green</option>
<option value="price3:25">red</option>
</select>
<input type="text" name="txtprice" id="txtprice" onClick="checkPrice()">
var select = document.getElementById('cmbitems');
var pecah = select.split(":");
var hasil = pecah[1];
var input = document.getElementById('txtprice');
select.onchange = function() {
input.value = hasil.value;
}
答案 0 :(得分:0)
尝试
var input = document.getElementById('txtprice');
document.getElementById('cmbitems').onchange = function() {
var select = document.getElementById('cmbitems').value;
var pecah = select.split(":");
var hasil = pecah[1];
alert(hasil);
input.value = hasil;
}
答案 1 :(得分:0)
试试这个
<select name="cmbitems" id="cmbitems">
<option value="price1:15">blue</option>
<option value="price2:20">green</option>
<option value="price3:25">red</option>
</select>
<input type="text" name="txtprice" id="txtprice">
var input = document.getElementById('txtprice');
var select = document.getElementById('cmbitems');
select.onchange = function() {
var pecah = select.options;
var hasil = pecah[pecah.selectedIndex];
input.value = hasil.value.split(":")[1];
}