[thelist] javascript - how to refer to (x)html elements

Joshua Olson joshua at waetech.com
Wed Nov 12 19:52:57 CST 2003


----- Original Message ----- 
From: "Tim Burgan" <burgan at iprimus.com.au>
Sent: Wednesday, November 12, 2003 7:29 PM


> <head>
>    <script type="text/JavaScript">
>         function collectInfo() {
>           var formNr = 0;
>           var elementName = "myName";
>           var element = document.forms[formNr].elements[elementName];
>           alert("The value is " + element.value);
>         }
>    </script>
> </head>

Tim,

As well as this does work in this case I've never been a big fan of
referring to the form by it's position within the page.  This can very
easily break down if another form gets placed above this one.  If you
encounter this problem, then you can alternately reference the form by its
id using document.getElementById.

Good luck,

<><><><><><><><><><>
Joshua Olson
Web Application Engineer
WAE Tech Inc.
http://www.waetech.com
706.210.0168



More information about the thelist mailing list