ShadowMage Posted September 25, 2009 Report Share Posted September 25, 2009 I'm having a rather strange issue with firefox. I have two functions, both using the getElementById() method. One works the other one doesn't.This is the first function, this one works: function doWhileTest() { var types = 1; var testVar; var locVar; while (document.getElementById("Test"+types)) { testVar = document.getElementById("Test"+types); locVar = document.getElementById("Loc"+types); locVar.value = testVar.value; types++; }} This is the function that doesn't work: function getSelectValue() { //The function works if I set mySelect this way //var mySelect = document.TestForm.testSelect; //It doesn't work when I use getElementById var mySelect = document.getElementById("testSelect"); var index = mySelect.selectedIndex; alert(mySelect.options[mySelect.selectedIndex].value);} What gives? Any help is appreciated. Thanks! Link to comment Share on other sites More sharing options...
jeffman Posted September 25, 2009 Report Share Posted September 25, 2009 (edited) var mySelect = document.TestForm.testSelect;The only way this will work is if your <select> element has an name attribute called "testSelect". And since it is very old-fashioned, this technique will never work in Firefox.var mySelect = document.getElementById("testSelect");This will work if your <select> element has an id called "testSelect". This technique will work in all modern browsers, including IE 6.What I'm wondering is if the <select> element really has both an id and a name called "testSelect", or if it only has a name called "testSelect". Edited September 25, 2009 by Deirdre's Dad Link to comment Share on other sites More sharing options...
ShadowMage Posted September 25, 2009 Author Report Share Posted September 25, 2009 Boy do I feel sheepish. I forgot to put an id on my select. Thank you! Can't believe I missed something so simple. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now