2012-12-29 105 views
1

我正在使用下面的腳本,需要在前兩個基礎上更改3個下拉列表的值,目前它顯示相同的值以改變第一個下​​拉列表中的值。這裏是腳本---通過javascript更改3個下拉值

<script type="text/javascript"> 

function changeprice(id){ 

    var value = id; 

    if(value == ""){ 
     document.getElementById('price').value=""; 
     alert("Please select one valid word count"); 
     return false; 
    } 
    if(value == "Lessthan1000"){ 
     var newprice = "USD 290"; 
    } 
    if(value == "Lessthan2000"){ 
     var newprice = "USD 540"; 
    } 
    if(value == "Lessthan4000"){ 
     var newprice = "USD 1050"; 
    } 
    if(value == "Lessthan6000"){ 
     var newprice = "USD 1900"; 
    } 
    var eprice = newprice; 

    document.getElementById('price').value = eprice; 

} 
</script> 

<select name="sp" id="sp" class="servicecategory"> 
    <option value="" selected>Please Select...</option> 
    <option value="Medical and Biomedical Manuscript Writing" <?php if($servicename == "Medical and Biomedical Manuscript Writing"){ echo(" selected=\"selected\""); } ?>>Medical and Biomedical Manuscript Writing</option> 
    <option value="Medical and Biomedical Manuscript Rewriting" <?php if($servicename == "Medical and Biomedical Manuscript Rewriting"){ echo(" selected=\"selected\""); } ?>>Medical and Biomedical Manuscript Rewriting</option> 
</select> 

<select name="Word_Count" id="Word_Count" onChange="changeprice(this.value)"> 
    <option value="" selected>Please Select...</option> 
    <option value="Lessthan1000">1 - 1000 words</option> 
    <option value="Lessthan2000">1001 - 2000 words</option> 
    <option value="Lessthan4000">2001 - 4000 words</option> 
    <option value="Lessthan6000">4001 - 6000 words</option> 
</select> 

<tr> 
    <td valign="top" align="right">Price:</td> 
    <td width="5"></td> 
    <td valign="top" align="left"><input type="text" name="price" id="price" value="" readonly="" size="20"><br /></td> 
</tr> 

需要改變的價值一旦我選擇醫療和生物醫學手稿重寫在第一個下拉列表中。任何建議現在要做什麼?爲醫學和生物醫學手稿其做工精細writing--三江源

回答

1

這裏,你可以作爲一個onchange事件中使用的函數:

HTML(注意onchange事件):

<select name="sp" id="sp" class="servicecategory" onChange="change_select_values(this.value)"> 

JS:

function change_select_values(val){ 
    var sel = document.getElementById('Word_Count'); 
    switch(val){ 
     case "Medical and Biomedical Manuscript Rewriting": 
      sel.options.length = 0; // clear select options 
      sel.options[0] = new Option('TEXT', 'VALUE'); 
      sel.options[1] = new Option('TEXT', 'VALUE'); 
      sel.options[2] = new Option('TEXT', 'VALUE'); 
      sel.options[3] = new Option('TEXT', 'VALUE'); 
      break; 
     default:   
      sel.options.length = 0; 
      sel.options[0] = new Option('1 - 1000 words', 'Lessthan1000'); 
      sel.options[1] = new Option('1001 - 2000 words', 'Lessthan2000'); 
      sel.options[2] = new Option('2001 - 4000 words', 'Lessthan4000'); 
      sel.options[3] = new Option('4001 - 6000 words', 'Lessthan6000'); 
    } 
    changeprice(sel.options[0].value); // change input value 
} 
+0

它不工作,不改變它們的值和它們的價格。:( – user1859847

+0

這隻會改變第二個選擇元素的選擇選項。如果你w螞蟻它改變輸入(價格),然後我會添加'changeprice(sel.options [0] .value);'在函數的末尾。我將修改代碼。 –

+0

此外,您需要擴展「changeprice」函數以包含新選項值 –