change the selected item in a dropdownlist in Mozilla

When an image is clicked, I want the value of the dropdown list to change.
The below (selectStyle.value = ) works for IE, but not for Mozilla.

sampleImg.Attributes.Add("onClick", " selectStyle.value = " + coverTypeRPOV.RetailerProductOptionValueID.ID + ";");
GeznaAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

mistledCommented:
Are you trying to change which item is selected?  Or the actual value of a specific option in the drop down?

Assuming that selectStyle is the id of the select box....

//set the value
document.getElementById('selectStyle').options[i].value == "new value";

//set the selected option
document.getElementById('selectStyle').options[i].selected = true;
OR
document.getElementById('selectStyle').selectedindex = i;  //where i is the index of the option you want to highlight

Either way, you will need to know which item in the list is the one you want to change and replace the [i] above with it (so "options[i]" becomes "options[2]" or whatever the index is.

If you don't know which item it is and are just trying to select the option that you have a known value for, try this....

var select = document.getElementById('selectStyle');
for ( var i = 0; i < select.options.length; i++) {
      if ( select.options[i].value == value) {
            select.selectedIndex = i;
      }
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
GeznaAuthor Commented:
I'm trying to change the item that is selected (visually)
My code actually works for IE, and I tried your last function (see below) and it works in IE as well.
However, in Mozilla Firefox, neither one works and the alert won't even fire.

//C#
//*********************
sampleImg.Attributes.Add("onClick", "setStyle(" + coverTypeRPOV.RetailerProductOptionValueID.ID + ");");

//javascript
//*************************
function setStyle(value){
var select = document.getElementById('selectStyle');
for ( var i = 0; i < select.options.length; i++) {
if ( select.options[i].value == value) {
select.selectedIndex = i;
}
}
alert(select.selectedIndex);
}
0
GeznaAuthor Commented:
I must have been doing something wrong, because after much disecting, I managed to get your code to work in Mozilla, such that it changes the dropdownlist value
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
C#

From novice to tech pro — start learning today.