HTML Submit-button: Different value / button-text?

HtmlForms

Html Problem Overview


I'd like to create an HTML form submit button with the value 'add tag', however, the web page is in Swedish, so I'd like to have a different button text.

That is, I want to have a button like

enter image description here

but I want to have my code like

if (request.getParameter(cmd).equals("add tag"))
    tags.addTag( /*...*/ );

Is this possible? If so, how?

Html Solutions


Solution 1 - Html

It's possible using the button element.

<button name="name" value="value" type="submit">Sök</button>

From the W3C page on button:

> Buttons created with the BUTTON element function just like buttons created with the INPUT element, but they offer richer rendering possibilities: the BUTTON element may have content.

Solution 2 - Html

Following the @greg0ire suggestion in comments:

<input type="submit" name="add_tag" value="Lägg till tag" />

In your server side, you'll do something like:

if (request.getParameter("add_tag") != null)
    tags.addTag( /*...*/ );

(Since I don't know that language (java?), there may be syntax errors.)

I would prefer the <button> solution, but it doesn't work as expected on IE < 9.

Solution 3 - Html

There are plenty of answers here explaining what you could do (I use the different field name one) but the simple (and as-yet unstated) answer to your question is 'no' - you can't have a different text and value using just HTML.

Solution 4 - Html

I don't know if I got you right, but, as I understand, you could use an additional hidden field with the value "add tag" and let the button have the desired text.

Solution 5 - Html

If you handle "adding tag" via JScript:

<form ...>
<button onclick="...">any text you want</button>
</form>

Or above if handle via page reload

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionaioobeView Question on Stackoverflow
Solution 1 - HtmlPekkaView Answer on Stackoverflow
Solution 2 - HtmlSony SantosView Answer on Stackoverflow
Solution 3 - HtmlijwView Answer on Stackoverflow
Solution 4 - HtmlFlinschView Answer on Stackoverflow
Solution 5 - HtmlAndrey PokhilkoView Answer on Stackoverflow