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

JavaScript code to loop through Dropdown list options not working in FireFox (works in IE)

Posted on 2007-12-03
Last Modified: 2013-12-07
This code works in IE but not in FF. Please help:

window.onload = blah;
function blah()
var which = document.getElementById('TheList');
  if(which.options[i].value == '" & Session("PreSelValue") & "')
    which.selectedIndex = i;
    window.document.Form2.elements['TheTextBox'].value = which.options[i].value; 

Open in new window

Question by:ishwarjoshi
  • 3
  • 2
LVL 29

Accepted Solution

Göran Andersson earned 500 total points
ID: 20398360




Author Comment

ID: 20401519
Thanks for the suggestion. That didn't work though. I put this in:


And it shows only a single blank alert. But the drop down list has 6 items.

This is an asp page. The drop down list in question is data-bound. This JavaScript code runs in the window.onload.

Do you think that the data bound list is not populated when this code runs? Maybe IE populates the list before the script runs and FireFox does not populate the list? That's my guess?

Please advise.

LVL 29

Expert Comment

by:Göran Andersson
ID: 20401618
Ok, then there is something more that is wrong...

Have you checked what the generated code looks like? Does the list contain the items? Does the list have exactly the id that you use in the code? Do you have any other element with the same id?

> Maybe IE populates the list before the script runs and FireFox does not populate the list?

Not at all. The data binding is done on the server, so the list contains the items before it's even sent to the browser. The browser has absolutely nothing to do with the data binding.

Author Comment

ID: 20407482
Thanks for your answer.
Hmmm. Yes I checked the generated code. The list does contain the items and it also has the same Id. Basically it all works perfectly in IE so not sure what's missing in FF.
Any other ideas?
LVL 29

Expert Comment

by:Göran Andersson
ID: 20407971
Usually when something like that happens, there is some error in the page, but it doesn't necessary have to be directly related to the code where you notice the problem. Firefox is a bit stricter about the correctness of the code, while IE accepts certain mistakes in the code. Difference in case of id:s/names or duplicate id:s are such things that may make a difference.

Other than what I mentioned before, I don't see anything wrong with the code that you have shown.

If you open the Error Console in Firefox and browse to your page, do you get any error messages?

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Several part series to implement Internet Explorer 11 Enterprise Mode
Today, still in the boom of Apple, PC's and products, nearly 50% of the computer users use Windows as graphical operating systems. If you are among those users who love windows, but are grappling to keep the system's hard drive optimized, then you s…
Google currently has a new report that is in beta and coming soon to Webmaster Tool accounts. This Micro Tutorial will highlight new features for Google Webmaster Tools.
Shows how to create a shortcut to site-search Experts Exchange using Google in the Chrome browser. This eliminates the need to type out site:experts-exchange.com whenever you want to search the site. Launch the Search Engine Menu: In chrome, via you…

808 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