Accessing hidden objects in a form

C

Craig Anderson

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

Java script Dude

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_notes/form_access.html#faComMis

JsD
 
R

Ralph Snart

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.forms['nameofform']['myHiddenObj'] should work *IF* the script fragment
comes physically after the form element on the page.

-rs-
 
T

Thomas 'PointedEars' Lahn

Ralph said:
On 1 Jul 2004 17:03:44 -0700, Craig Anderson <[email protected]> wrote:

Please do not write attribution novels. The information you have
included is already contained in the headers of the involved postings.
Only the poster's name is required to see who wrote what of the quoted
text. said:
[...]
document.forms['nameofform']['myHiddenObj'] should work *IF* the
script fragment comes physically after the form element on the page.

When a DOM object becomes available depends on the DOM, on the UA.
Furthermore, your referencing is neither standards compliant nor
backwards compatible. The following is both:

document.forms['nameofform'].elements['myHiddenObj']

However, in most cases relative referencing, such as starting
from the (parent) form element with `this' or `this.form' in
an event handler, will suffice.


PointedEars
 
D

Dr John Stockton

JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn
wrote:

Please do not write attribution novels. The information you have
included is already contained in the headers of the involved postings.
Only the poster's name is required to see who wrote what of the quoted
text. <http://www.netmeister.org/news/learn2quote.html>


The current Internet draft REQUIRES more than that, and is quite
encouraging to those who wish to provide more than is strictly called
for.
http://www.ietf.org/internet-drafts/draft-ietf-usefor-useage-00.txt

Please stop trying to be a petty dictator; Mussolini at least did (or so
I have heard) something towards getting the trains to run on time, and
dictatorial mis-rule is nowadays considered passé.



Aside : ISTM that the "stringy" LZ is a little slower than the numeric
one; unless others find otherwise, it's probably best used only
for bases other than 10.



TL wrote elsewhere :
The word "I" is always capitalized in English.

Unfamiliar with e e cummings, then?
 
G

Grant Wagner

Dr said:
JRS: In article <[email protected]>, seen in
Thomas 'PointedEars' Lahn


The current Internet draft REQUIRES more than that, and is quite
encouraging to those who wish to provide more than is strictly called
for.
http://www.ietf.org/internet-drafts/draft-ietf-usefor-useage-00.txt

Please stop trying to be a petty dictator; Mussolini at least did (or so
I have heard) something towards getting the trains to run on time, and
dictatorial mis-rule is nowadays considered passé.

What I find most annoying is that he claims such "attribution novels" waste
bandwidth and make it harder to follow the flow of the usenet post, but Thomas'
responses to such "novels" are longer (thereby wasting _more_ bandwidth) and
disrupt the flow of the post even further.

Much like banner ads on Web sites, I mentally "tune out" the noise introduced by
quoted material on usenet, but his responses to the noise appear at first to
contain meaningful information. It is only after I have read most of his response
that I realize it is nothing more then additional noise.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,535
Members
45,007
Latest member
obedient dusk

Latest Threads

Top