簡體   English   中英

使用split()從選擇下拉列表中填充文本字段值

[英]filled textfield value from select dropdown with split()

當我使用split()時,textfield的值為空,下拉列表中需要的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;
}

嘗試

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;
}

嘗試這個

<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];
 }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM