Very simple question I hope.
I have the usual <select>
box like this
<select id="select">
<option value="1">this</option>
<option value="2">that</option>
<option value="3">other</option>
</select>
I can get the selected value (by using $("#select").val()
) and the selected item's display value (by using $("#select :selected").text()
.
But how can I store like an additional value in the <option>
tag? I would like to be able to do something like <option value="3.1" value2="3.2">other</option>
and get the value of the value2
attribute (which would be 3.2 in the example).
To store another value in select options:
I made two examples from what I think your question might be:
http://jsfiddle.net/grdn4/
Check this out for storing additional values. It uses data attributes to store the other value:
http://jsfiddle.net/27qJP/1/
HTML/JSP Markup:
JQUERY CODE: Event: change
To have a element libelle.val() or libelle.text()
To me, it sounds like you want to create a new attribute? Do you want
To do this, you can do
And then to retrieve it, you can use
It's not going to be valid code, but I guess it does the job.
HTML Markup
Code
See this as a working sample using jQuery here: http://jsfiddle.net/GsdCj/1/
See this as a working sample using plain JavaScript here: http://jsfiddle.net/GsdCj/2/
By using data attributes from HTML5 you can add extra data to elements in a syntactically-valid manner that is also easily accessible from jQuery.