这是我第一次参加此活动。我正在尝试创建一个具有一些下拉选项的脚本。我需要从最后一个下拉列表中获取值,然后我需要将该值乘以输入数字。
我还没有创建输入号码,因为我不知道如何从价格中获取数据。 基本上当它显示价格时,我需要这个价格才能有输入数字区域与价格相乘。
我的小提琴就在这里:http://jsfiddle.net/blaxxzg/sy95ksnL/
var stateObject = {
"Mali format": {
"2/5 cm": ["9,5 €"],
},
"Mali format-tanki": {
"1/3,5 cm": ["12,13 €"],
},
"Veliki format": {
"3/7 cm": ["20,15 €"],
},
"Veliki format-tanki": {
"2/4 cm": ["18,79 €"],
}
}
window.onload = function () {
var stateSel = document.getElementById("stateSel"),
countySel = document.getElementById("countySel"),
citySel = document.getElementById("citySel");
for (var state in stateObject) {
stateSel.options[stateSel.options.length] = new Option(state, state);
}
stateSel.onchange = function () {
countySel.length = 1; // remove all options bar first
citySel.length = 1; // remove all options bar first
if (this.selectedIndex < 1) {
countySel.options[0].text = "Prvo odaberite tip kamena"
citySel.options[0].text = "Prvo odaberite debljinu kamena"
return; // done
}
countySel.options[0].text = "Please select county"
for (var county in stateObject[this.value]) {
countySel.options[countySel.options.length] = new Option(county, county);
}
if (countySel.options.length==2) {
countySel.selectedIndex=1;
countySel.onchange();
}
}
stateSel.onchange(); // reset in case page is reloaded
countySel.onchange = function () {
citySel.length = 1; // remove all options bar first
if (this.selectedIndex < 1) {
citySel.options[0].text = "Please select county first"
return; // done
}
citySel.options[0].text = "Please select city"
var cities = stateObject[stateSel.value][this.value];
for (var i = 0; i < cities.length; i++) {
citySel.options[citySel.options.length] = new Option(cities[i], cities[i]);
}
if (citySel.options.length==2) {
citySel.selectedIndex=1;
citySel.onchange();
}
}
}
答案 0 :(得分:0)
Here is the solution you are looking for 我已经为最后一次下拉添加了onchange。
citySel.onchange = function(){
document.getElementById('PicExtPrice').value=this.options[this.selectedIndex].value;
}