ShadowMage Posted September 25, 2009 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 Share Posted September 25, 2009 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". Link to comment Share on other sites More sharing options...
ShadowMage Posted September 25, 2009 Author 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
Archived
This topic is now archived and is closed to further replies.