Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17


change the selected item in a dropdownlist in Mozilla

Posted on 2007-04-10
Medium Priority
Last Modified: 2008-02-01
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 + ";");
Question by:Gezna
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2

Accepted Solution

mistled earned 2000 total points
ID: 18885165
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;
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;

Author Comment

ID: 18885525
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.

sampleImg.Attributes.Add("onClick", "setStyle(" + coverTypeRPOV.RetailerProductOptionValueID.ID + ");");

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;

Author Comment

ID: 18885949
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

Featured Post

Certified OpenStack Administrator Course

We just refreshed our COA course based on the Newton exam.  With 14 labs, this course goes over the different OpenStack services that are part of the certification: Dashboard, Identity Service, Image Service, Networking, Compute, Object Storage, Block Storage, and Orchestration.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

721 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question