我有兩個帶有選擇值的下拉列表。我已完成功能部分,其中從兩個下拉列表中選擇的值將顯示在testPoint.html
頁面中(如函數所示)。現在,我想根據在Profile
下拉列表中選擇的配置文件分開頁面。JavaScript - 根據從下拉列表中選擇的值重定向到頁面
例如,當用戶從下拉列表中的「FULL」選項,網頁會被重定向到「testPointDRC.html」
需要幫助的這一個。
(function() {
function onSubmitClicked(event) {
var product = document.getElementById('product'),
productVal = product.value,
profile = document.getElementById('profile'),
profileVal = profile.value;
url = 'testPoint.html?product=' + encodeURIComponent(productVal) + '&profile=' + encodeURIComponent(profileVal);
location.href = url;
if (profileVal = "Full DRC") {
url = "testPointDRC.asp";
}
}
var submitButton = document.getElementById('btngo');
submitButton.addEventListener('click', onSubmitClicked);
})();
<table>
<tr>
<td>
<h4>Choose a Product  : </h4>
<select id="product">
\t <optgroup label="DEFAULT">
\t <option value = "NONE">NONE</option>
\t </optgroup>
\t </select>
<br><br>
<h4>Choose a Profile    : </h4>
<select id="profile">
\t
\t <optgroup label="DEFAULT">
\t <option value = "NONE">NONE</option>
\t </optgroup>
\t <optgroup label="TEST PROFILES">
\t <option value = "Full">FULL</option>
\t <option value = "QC">QC</option>
\t <option value = "Cold">COLD</option>
\t <option value = "Hot">HOT</option>
\t <option value = "Room">ROOM</option>
\t </optgroup>
\t </select>
</td>
</tr>
</table>
<br><br><br>
<input type="submit" id="btngo" value="Go" class="button button2" />
使用window對象並設置'window.location.href'等於重定向URL。 –
非常感謝您的反饋。我有很多選擇需要重定向到各種頁面。 '如果和其他'條件是我需要的。再次感謝你,蕾! :) – xerxes39