2012-06-26 27 views
0

我有下面的JavaScript函數去選擇框值url。在選擇框上使用javascript轉到url DropDown框

function go(x) { 
    alert(x); 
    location = x.value; 
} 

爲用戶的不同 我寫一個PHP打印表格和DIV裏面所有的選擇框,我不能使用的getElementById 可能有超過1個選擇框

<div class="styled-select"> 
    <form name="menu"> 
     <select id=Admission onchange=go(this)> 
      <option value=/admission>Add Existing Students</option> 
     </select> 
     <select id=Student onchange=go(this)> 
      <option value=www.bing.com>Student Details</option> 
     </select> 
    </form> 
</div> 

所有建議都歡迎。

回答

3

您不能正確訪問元素的值。使用這個來代替:

function go(x) { 
    location = x.options[x.selectedIndex].value; 
} 

你也不會永遠只一個選項得到onchange事件的<select>

+0

謝謝@thiefmaster –

+0

如果這是您需要的答案,請將其標記爲已接受! –