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>
No, there is no such requirement.
select elements do not have a value attribute.
</option> , value="" is turned into just value . The value, when set to the empty string is simply discarded.
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>
<!-- With Value -->
key: 'values' value: 'with-value'
<!-- Without Value -->
key: 'values' value: 'Without Value'
<!-- Without Empty Value -->
key: 'values' value: ''
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With