我是一個非常初學JavaScript的人,我想在用戶選擇一個表單的選項時,改變一個輸入值,然後將它提交給同一頁面。如何在提交使用javascript之前更改隱藏的輸入值?
這裏是HTML代碼:
<form id="form" action="thispage.jsp" method="post">
<input id="action_type" type="hidden" name="action_type" value="firstAction" />
<table class="choose">
<tr>
<td>Choose your test</td>
<td><select id="select_test" name="test_name">
<option value="test0"></option>
<option value="test1"></option>
</select></td>
</tr>
</table>
以及JavaScript函數:
form = document.getElementById("form");
action = document.getElementById("action_type");
select = document.getElementById("select_test");
select.onchange = function() {
action.setAttribute("value", "otherAction");
form.submit();
}
這將返回一個例外,什麼是錯的代碼?
正在返回什麼異常? –
正如我對費邊所說,這是來自org.apache.jsp.someGeneratedClass._jspService的NullPointerException – floribon