[thelist] [javascript] getElementById

Paul Bennett paul at teltest.com
Wed Oct 23 19:18:01 CDT 2002


Unfortunately, the page in question is being used on my machine as I
test some changes to the php/mysql project tracking system we have
developed, so no outside url.
Thanks for the tips.
FYI, that value I was trying to access was in a select list - would that
change the elements properties?
I thought that it would still have a value property in a similar manner
to a textbox, as this is set in the "option" tag
I felt it would be simpler to pass the id of the select list to the
getElementById method and get the value from there, rather than having
to write the
entire path through the document object to the select list property in
the function call (inside a link) as the page has quite a few calls to
the same function.
I can now see, however, that simply declaring a "shortcut" var in the
function and appending the parameter passed to it would accomplish the
same purpose. (phew!)

.jeff wrote:

>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/
>
>
>

--
Paul Bennett
Internet Developer
Teltest Electronic Design
--------------------------
Phone : 64 4 237 0767
Web : http://www.teltest.com
Wap : http://wap.teltest.com
Email : paul at teltest.com
--------------------------





More information about the thelist mailing list