javascript - referencing multiple values inside an option element -


similar question can option in select tag carry multiple values? - except want reference values in javascript

to recap:
want return more 1 value selected item in selectbox - thinking this:

<select id='selectlist'>    <option value1="a" value2="b" value3="c">option 1</option>    <option value1="d" value2="e" value3="f">option 2</option> </select> 

i want values of selected item:

var sel = document.getelementbyid('selectlist'); selvalue1 = sel.options(sel.selectedindex).value1; selvalue2 = sel.options(sel.selectedindex).value2; selvalue3 = sel.options(sel.selectedindex).value3; 

currently can pull value='x' option need more values associated option. delimit 3 values 1 , later use string functions split them out, seem nasty.

i think looking attributes property:

var sel = document.getelementbyid('selectlist');  selvalue1 = sel.options[sel.selectedindex].attributes.value1.value; 

here jsfiddle demonstrating how extract these values.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -