-3

I have the following problem that I can't solve:

I have this form into an HTML table:

<th width = "8.33%">
    <form id="actionButton" action="salwf.do?serv=1" method="post">
        <button name="accept" value="Accept" type="submit" class="acceptButton">ACCEPT ICON BUTTON</button>
        <button name="cancel" value="Cancel" type="submit" class="cancelButton">CANCEL ICON BUTTON</button>
        <button name="sap" value="SAP" type="submit" class="sapButton">SAP ICON BUTTON</button>
        <input id="testId" name="test" type="hidden">
    </form>
</th>

As you can see this form contains three jQuery button elements and an hidden input tag.

I need to create a JavaScript that do the following operations: when the user click on one of the previous three buttons it take the value of the clicked button (Accept or Cancel or SAP) and submit it (in a POST request).

Can I do something like this using JavaScript? How can I implement it?

Brian Tompsett - 汤莱恩
  • 5,753
  • 72
  • 57
  • 129
AndreaNobili
  • 40,955
  • 107
  • 324
  • 596

1 Answers1

0

I need to create a Javascript that do the following operations: when the user click on one of the previous 3 buttons it take the value of the clicked button (Accept or Cancel or SAP) and submit it (in a POST request).

The value is submiited along with the request by itself. You have different names, so check the presence of that name while processing your form request in post parameters.

Accept:Accept
Cancel:Cancel
SAP:SAP

Alternatively, what you can do is, to give your buttons different id but same name.

<button id="accept" name="ctrl" value="Accept" type="submit" class="acceptButton">ACCEPT</button>
<button id="cancel" name="ctrl" value="Cancel" type="submit" class="cancelButton">CANCEL</button>
<button id="sap" name="ctrl" value="SAP" type="submit" class="sapButton">SAP</button>

Then you can check the form request which will contain your value with the same key:

ctrl:Accept
ctrl:Cancel
ctrl:SAP

If you have different names, you will have a different key for every button.

Abhitalks
  • 27,721
  • 5
  • 58
  • 81