2017-04-12 151 views
-2

這是我第一次在這裏。我試圖創建一個有一些下拉選項的腳本。我需要從最後一個下拉列表中獲取值,然後我需要將該值與輸入數字相乘。從下拉列表中獲取數據javascript

我還沒有創建輸入號碼,因爲我不知道如何從價格中獲取數據。 基本上,當它顯示的價格,我需要這個價格能夠有輸入數字區域乘以價格。

我的小提琴是在這裏: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

我不知道你在問什麼。究竟是什麼問題? – Seany84

+0

這裏是你的小提琴的更新。讓我知道這是你在找什麼http://jsfiddle.net/rrnufjyt/1/ –

+0

是的,這就是我一直在尋找。非常感謝你。 @VijendraKulhade –

回答

0

Here is the solution you are looking for 我已經添加了最後的下拉電平變化。

citySel.onchange = function(){ 
document.getElementById('PicExtPrice').value=this.options[this.selectedIndex].value; 
    } 
+0

謝謝,我剛剛添加了3盒,盒子1顯示citysel和多數民衆贊成,但如何繁殖box1與box2(box2必須是免費輸入的數字)然後顯示在結果框中,也許你可以在這裏幫助嗎? https://jsfiddle.net/blaxxzg/sy95ksnL/4/ –

相關問題