[thelist] [javascript] getElementById
.jeff
jeff at members.evolt.org
Wed Oct 23 18:27:01 CDT 2002
paul,
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Paul Bennett
>
> I have been able to use the function successfully by
> simply passing the reference as:
> document.forms.form_name.UserOptions.value, but thought
> I would try something a bit more efficient for this page
> seeing as it uses the dame function so many times.
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
using the getElementById() method is far less efficient than simply using the DOM 0 notation you're currently using as the getElementById() method has to execute each time you do a lookup. if you want to make your code less bulky, try assigning an object reference to a variable and using that variable to access the properties of the form element:
var myVar = document.forms['form_name'].elements['UserOptions'];
var myVarValue = myVar.value;
var myVarType = myVar.type;
now, to answer your question about the getElementById() method, are you using it like this:
function alertValue(elementID)
{
myElement = document.getElementById(elementID);
alert(myElement.value);
}
with a form field like this:
<input type="text" name="username" id="username" ...>
and calling the function like this:
alertValue('username');
????
if not, compare where your method differs. if so, maybe post a link to the page that has an example of what you're struggling with.
thanks,
.jeff
http://evolt.org/
jeff at members.evolt.org
http://members.evolt.org/jeff/
More information about the thelist
mailing list