开发者

short circuit onchange="submit()"

开发者 https://www.devze.com 2023-01-30 04:46 出处:网络
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 s

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>
0

精彩评论

暂无评论...
验证码 换一张
取 消