473,403 Members | 2,183 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,403 software developers and data experts.

Accessing hidden objects in a form

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?
Jul 23 '05 #1
5 2422
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
Jul 23 '05 #2
On 1 Jul 2004 17:03:44 -0700, Craig Anderson <cr************@vykor.com> wrote:
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-
Jul 23 '05 #3
Ralph Snart wrote:
On 1 Jul 2004 17:03:44 -0700, Craig Anderson <cr************@vykor.com> 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>
[...]
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
Jul 23 '05 #4
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Sat, 10 Jul 2004 02:30:11 :
Ralph Snart wrote:
On 1 Jul 2004 17:03:44 -0700, Craig Anderson <cr************@vykor.com>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/...-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?

--
© John Stockton, Surrey, UK. ?@merlyn.demon.co.uk Turnpike v4.00 MIME ©
Web <URL:http://www.uwasa.fi/~ts/http/tsfaq.html> -> Timo Salmi: Usenet Q&A.
Web <URL:http://www.merlyn.demon.co.uk/news-use.htm> : about usage of News.
No Encoding. Quotes before replies. Snip well. Write clearly. Don't Mail News.
Jul 23 '05 #5
Dr John Stockton wrote:
JRS: In article <40**************@PointedEars.de>, seen in
news:comp.lang.javascript, Thomas 'PointedEars' Lahn
<Po*********@nurfuerspam.de> posted at Sat, 10 Jul 2004 02:30:11 :
Ralph Snart wrote:
On 1 Jul 2004 17:03:44 -0700, Craig Anderson <cr************@vykor.com>

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

--
Grant Wagner <gw*****@agricoreunited.com>
comp.lang.javascript FAQ - http://jibbering.com/faq
Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Esben Rune Hansen | last post by:
Hi I am working on a PHP-script and need javascript to set the value of a hidden field in a form. This field happens to be an entry in an array data according to my example. How can I do this? ...
18
by: Choxio | last post by:
Using ASP you can access posted form elements. Is it possible to access them from JavaScript? myHTML.htm <form action=myASP.asp> <input type=hidden id=f1 value=val1> <input type=hidden...
1
by: Andrew Wrigley | last post by:
Hi Should a hidden form become visible when all other forms are closed? This is what happens, and to ensure that it is always hidden, I have to set the on got focus event handler of the form...
3
by: Jeremy Ames | last post by:
I have a form that contains two hidden values, among other controls. I was wondering, if I change these values in server script and immediately do a server.transfer, do these values get updated...
1
by: CS Wong | last post by:
Hi, I have a page form where form elements are created dynamically using Javascript instead of programatically at the code-behind level. I have problems accessing the dynamically-created...
1
by: j.eckles | last post by:
I'm trying to determine if there is a way in VBScript, perhaps via ADO or DAO, to access what I'll term MS Access "object groups". What I mean by "object groups" are the folders that you see under...
19
by: k.karthikit | last post by:
Hello all, In some hidden variable (<input type="hidden" name="hiddenId" value="test" /> ,i stored some value.I accessed the value "test" using var id = document.getElementById( 'hiddenId' );...
0
by: sonu | last post by:
I have following client side code which i have used in my asp.net project SummaryFeatured Resources from the IBM Business Values Solution Center WHITEPAPER : CRM Done Right Improve the...
1
by: Vinodsrvk | last post by:
I am accessing a string from the previous page's hidden text. While I am reading the string the only last character of the string is getting truncated. When I tried viewing the string in the previous...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.