short circuit onchange="submit()"
As the title states, I would like to short开发者_如何学C circuit the onchange (inside of a select). I have the following code but I would just like to send a hard-coded value without ever showing the selection box.
<SELECT name="select_applet_instance" onchange="submit()">
<% for (int i = 0 ; i <serviceBean.getinfo().size() ; i++){%>
<OPTION value="<%=i%>"><%= serviceBean.getinfo().get(i) %></OPTION>
<% }%>
</SELECT>
[edit]
Sorry, I was not clear. I don't even want to offer a selection, I know what value I want to submit, I want to set that value and just forward the page [/edit]If you don't want to show anything at all but redirect the user immediately:
<input type="hidden" value="4" name="select_applet_instance" />
<script>yourformhere.submit()</script>
Now the moment the browser reads the <script>
tag, it will submit the form.
You need to submit the form element. You can do that by referencing the form and calling submit on it:
<SELECT name="select_applet_instance" onchange="document.getElementById('yourFormsID').submit()">
<% for (int i = 0 ; i <serviceBean.getinfo().size() ; i++){%>
<OPTION value="<%=i%>"><%= serviceBean.getinfo().get(i) %></OPTION>
<% }%>
</SELECT>
精彩评论