Septagram
Septagram

Reputation: 9785

How to assign an arbitrary value to a variable when user clicks submit button?

A submit button allows to send it's name and value attributes along with the rest of request, when it is clicked, allowing to remember which one of submit buttons was used to send the form data. However, the value sent must be the same text that is displayed on the button. Is there any way for a submit button to send an arbitrary value instead of button text, preferably the way that does not rely on user having JavaScript enabled? Also, is the answer to this question somehow different for XHTML and HTML5?

Upvotes: 0

Views: 120

Answers (2)

Robin Drexler
Robin Drexler

Reputation: 4457

Try using a button element.

<form method="post">
    <button name="abutton" value="abc">foo</button>
</form>​​​​​​​​​​

http://jsfiddle.net/54DfJ/

Upvotes: 1

Evan Davis
Evan Davis

Reputation: 36592

Use a button instead of an input:

<button id="butter" type="submit" value="go">Let's do it</button>​

Example: http://jsfiddle.net/duySv/

That way the label and value are separate.

https://developer.mozilla.org/en/HTML/Element/button

Upvotes: 4

Related Questions