Jump to content

Getelementbyid Only Sometimes Works


ShadowMage

Recommended Posts

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...