我是一个非常初学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