[Javascript] how to refer to (x)html elements

David Lovering dlovering at gazos.com
Wed Nov 12 09:18:38 CST 2003


Yes, but there are a few caveats.

  var myForm = document.getElementById("form_example");
  var myObject = myForm.getElementById("input_example");

BTW -- you can't reuse an id like "example" for both an input object and a
form, and expect things to work OK.

The caveats are that not every browser will permit you to do this (the
getElementById call was defined originally for IE), and secondly, the HTML
object id may not necessarily map to the XML id.  I've had some problems
with this myself, and the XML
id only works flawlessly when it is defined within an XML construct.
However, it SHOULD work -- providing that the object is "dual-homed" and is
identified with both an XML and HTML label.

Mind you, under IE6+ I've been able to make XML reference HTML objects with
only the HTML id's in place, but I've no illusions that this is correct,
portable, or even a very good way to do things.

-- Dave Lovering

----- Original Message ----- 
From: "Tim Burgan" <lists.latech.edu at greaterthani.com>
To: "[JavaScript List]" <javascript at LaTech.edu>
Sent: Tuesday, November 11, 2003 9:45 PM
Subject: [Javascript] how to refer to (x)html elements


> hello,
>
> as i've been trying to learn javascript - i'm a little stuck.. again
>
> I don't know how to explain this, but instead of:
>
>   document.formName.inputName.value
>   (eg. <form name="example"> <input name="example">)
>
> i want to use:
>
>   document.formId.inputId.value
>   (eg. <form id="example"> <input id="example" />)
>
> the reason being, that to use the first example I must use
> non-standards-compliant xhtml code in my documents.
>
> So is there a way that JavaScript can use xhtml tag's ID elements rather
> than the depreciated NAME element?
>
> Thanks
> Tim Burgan
>
> _______________________________________________
> Javascript mailing list
> Javascript at LaTech.edu
> https://lists.LaTech.edu/mailman/listinfo/javascript
>
>





More information about the Javascript mailing list