Get value and name from select option?

I need to get 2 variables from a select box when a selection is made. so I stored one variable as the name attribute and the other as the value attribute.

I am using a function to get these like this:

function blue_diamond_selected() {
var select_box = document.getElementById(“blue_diamond_select_box”);
var option_value = select_box[select_box.selectedIndex].value;
var option_name = select_box[select_box.selectedIndex].name;

this works in IE but in FF it is not getting the name just the value…the name comes up as undefined.

Can someone help me? or if I am going about this completely wrong how should I do it?


OK I used title instead of name and that worked.

Can you please give us a sample of the html code and how you want to use it?

It seems that the current technique is going against good practices, so we should be able to come up with a more workable solution for you.

                            <select id="blue_diamond_select_box" name="blue_diamond_select_box" onchange="blue_diamond_selected()">

                                <option value="1-37222" title="14k WG">.24 Ct. 14k WG $210</option>

                                <option value="1-80584" title="14k WG">.27 Ct. 14k WG $315</option>

                                <option value="1-80720" title="14k WG">.29 Ct. 14k WG $330</option>

Theres actually several options I just showed a few for simplicity. the value is needed for the actual form processing. but when they change the selection I want to update a picture to either show a white gold ring or a yellow fold ring depending on the selection. thats why I have that in the title. its currently working the way I have it here:


From what you’ve said it seems that using a class name instead of the title would be an improvement for storing the type of ring.