2011-11-02 37 views
0

我嘗試重定向頁面取決於用戶是否在下拉菜單中選擇「標準」或「維護」。 Hoewever我的JavaScript不太工作。你能幫我指點我哪裏錯了嗎?JavaScript重定向頁面基於選定的值

在此先感謝。

<script type="text/javascript"> 
    <!-- 
    function formType(value){ 
     if (value == 'maintenance') { 
      window.location = "index.php?requestType=maintenance"; 
     } else { 
      window.location = "index.php?requestType=standard"; 
     } 
    --> 
    </script> 
    <select id="changer" name="type" onchange="formType(this.value);"> 
       <option value="standard" <?php if ($requestType == 'standard') { echo "selected"; } ?>>Standard</option> 
       <option value="maintenance" <?php if ($requestType == 'maintenance') { echo "selected"; } ?>>Maintenance</option> 
    </select> 
+0

'function formType(value){window.location =「index.php?requestType =」+ value; }' –

回答

2

您在函數結束時缺少}

+0

謝謝!我現在覺得缺少這麼簡單的東西是愚蠢的... –

0

有一個}在你的函數結束時丟失。它應該看起來像這樣:

function formType(value){ 
    if (value == 'maintenance') { 
     window.location = "index.php?requestType=maintenance"; 
    } else { 
     window.location = "index.php?requestType=standard"; 
    } 
}