Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Let's say that I have this select. If I post this, the value would be: city 1, city 2, city 3 and city 4. I don't want to give them a value, because the value is the same as the option-name.

Is this okay?

<select>
    <option>City 1</option>
    <option>City 2</option>
    <option>City 3</option>
    <option>City 4</option>
</select>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
524 views
Welcome To Ask or Share your Answers For Others

1 Answer

If there is no value your text will be used. You can find this information on the HTML standard:

The value attribute provides a value for element. The value of an option element is the value of the value content attribute, if there is one, or, if there is not, the value of the element's text IDL attribute.
https://html.spec.whatwg.org/multipage/forms.html#the-option-element

or on the W3C Wiki

Provides a value for element. If there isn't, the value of an option element is the textContent of the element.
https://www.w3.org/wiki/HTML/Elements/option

Test Case

With the following snippet you can test the behaviour of the options: http://jsfiddle.net/ghqp08kr/

<form action="http://posttestserver.com/post.php" method="post">
  <select name="values">
    <option value="with-value">With Value</option>
    <option>Without Value</option>
    <option value="">With Empty Value</option>
  </select>
  <input type="submit"/>
</form>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...