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

Tim Burgan burgan at iprimus.com.au
Wed Nov 12 18:29:27 CST 2003


Hello,

The final code is - that does validate with the W3C validator
<http://validator.w3.org/>

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

<form action="" method="">
      <input type="text" name="myName" />
      <input type="button" value="submit" onclick="collectInfo();" />
</form>

I 'name' attribute in the 'form' tag is not compliant with XHTML 1.0 Strict or
XHTML 1.1, but it is allowed to be used with 'input' tags. Multiple 'id'
attributes are not allowed on the same page. The way the JavaScript refers to
the elements here, it's not needed - thanks to .Jeff and Kristof.

Thank you everyone for your help - you can see a working example of this at:
<http://www.greaterthani.com/05_programming/week5a.htm>

Thanks
Tim Burgan




More information about the thelist mailing list