cr************@vykor.com (Craig Anderson) wrote in message news:<ea*************************@posting.google.c om>...
Can anyone tell me the best way to access a hidden object in a form? I
could use a hard-coded index to the elements of the form, but it's too
easy to add something before the hidden object and mess up the
indexing.
For example:
The form has a tagid of "myForm"
The hidden object has a tagId of "myHiddenObj"
I can get the form elements by using
var formElements = document.getElementById('myForm').elements
But there doesn't seem to be any way to do this:
document.getElementById('myHiddenObj')
Assuming I have the elements as obtained above, none of these have
worked for me either:
formElements['myHiddenObj']
formElements["myHiddenObj"]
formElements.myHiddenObj
Anyone have an idea?
document.getElementById is for accessing HTML elements with id's. If
there is no ID, you will not see them. Unfortunately ID access is
slow as the data is not efficiently indexed. Instead access through
document.forms...
Use form document.forms['formname'] and for the elements, I prefer to
use the shortcut to the elements
document.forms['formname']['formelemname']. This syntax works smoothly
in Mozilla and IE.
I generally assign the form to a global variable `oF` since I commonly
access it more that once in my code
(window.oF=document.forms['formname']). I Then reference with the
shortcut accessor oF['myHiddenObj'] to access form elements in. This
syntax is the the most compact and should be efficient. I have not
tested this syntax outside of Moz and IE though. For standards
compliant access, use document.forms['formname'].elements['elemname'].
There is one known bug in IE with the shortcut syntax above whereas if
the form element names start with a number ( which it should not
anyway ) IE cannot find them.
For additional info check out javascript FAQ -
http://www.jibbering.com/faq/faq_not....html#faComMis
JsD