简体   繁体   English

带有多个按钮的表单

[英]Form with multiple buttons

I am having a form with a submit button and a input button. 我有一个带有提交按钮和输入按钮的表单。 I want to send a parameter to servlet on form submission. 我想在表单提交时向servlet发送一个参数。

<form action="postValues">
  <table>....</table>
  <input type="submit" name"event" value="add"/>
  <input type="button" name="event" value="refresh" onclick="getValues()"/>
</form>

When I click on submit in servlet I am getting "event" value in request parameter but on clicking refresh in servlet I am not getting the value for "event" in refresh parameter. 当我单击servlet中的Submit时,我在请求参数中得到了“事件”值,但是单击servlet中的刷新时,我没有得到刷新参数中的“事件”值。 I need that javascript function "getValues", where I need to get the values of table cells. 我需要那个javascript函数“ getValues”,在这里我需要获取表单元格的值。

How can I send the parameter to servlet when this input type is button? 当输入类型为button时,如何将参数发送到servlet?

If you click on the "refresh" button then the "getValues()" javascript function is responsible to communicate the server it will not submit the form. 如果单击“刷新”按钮,则JavaScript函数“ getValues()”负责与服务器进行通信,它将不提交表单。 so, you need to send the button value separately. 因此,您需要单独发送按钮值。 you can try this, 你可以试试看

<input type="button" name="event" value="refresh" onclick="getValues(this)"/>

so in the getValues function you'll get this event button reference, so you can send the value of button on query string. 因此,在getValues函数中,您将获得此事件按钮引用,以便可以在查询字符串上发送button的值。

eg: 例如:

function getValues(button){
    var buttonValue = button.value;
    //send this value in your query string.
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM