Why do I need to give my options a value attribute in my dropdown? JQuery.
- by Alex
So far in my web developing experiences, I've noticed that almost all web developers/designers choose to give their options in a select a value like so:
<select name="foo">
<option value="bar">BarCheese</option>
// etc.
// etc.
</select>
Is this because it is best practice to do so? I ask this because I have done a lot of work with jQuery and dropdown's lately, and sometimes I get really annoyed when I have to check something like:
$('select[name=foo]').val() == "bar");
To me, many times that seems less clear than just being able to check the val() against BarCheese. So why is it that most web developers/designers specify a value paramater instead of just letting the options actual value be its value?