By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,247 Members | 1,165 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,247 IT Pros & Developers. It's quick & easy.

FAQ Topic - How do I get the value of a form control?

P: n/a
-----------------------------------------------------------------------
FAQ Topic - How do I get the value of a form control?
-----------------------------------------------------------------------

In HTML documents, named forms may be referred to as named
properties of the document.forms collection, and named form
controls may be referred to as named properties of the form's
elements collection:

var frm = document.forms["formname"];
var contrl = frm.elements["elementname"];

The (string) value property of such controls can be read
directly from the element:-

var value = contrl.value;
var value = (+contrl.value); //string to number: see 4.21

Some exceptions would be:

First Exception: Where the control is a SELECT element, and
support for older browsers, such as NN4, is required:

var value = contrl.options[contrl.selectedIndex].value;

Second Exception: Where several controls share the same name,
such as radio buttons. These are made available as collections
and require additional handling. For more information, see:-

http://www.jibbering.com/faq/faq_notes/form_access.html

Third Exception: File Inputs where most current browsers do not
allow the reading of type="file" input elements in a way that is useful.
===
Postings such as this are automatically sent once a day. Their
goal is to answer repeated questions, and to offer the content to
the community for continuous evaluation/improvement. The complete
comp.lang.javascript FAQ is at http://jibbering.com/faq/index.html.
The FAQ workers are a group of volunteers.

Feb 19 '07 #1
Share this Question
Share on Google+
3 Replies


P: n/a
FAQ server wrote on 19 feb 2007 in comp.lang.javascript:
In HTML documents, named forms may be referred to as named
properties of the document.forms collection, and named form
controls may be referred to as named properties of the form's
elements collection:
I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms['..'].elements['..']

Do not let terrible MS asp.net terminology sip into this FAQ.

--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 19 '07 #2

P: n/a
On Feb 19, 9:55 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
FAQ server wrote on 19 feb 2007 in comp.lang.javascript:
>In HTML documents, named forms may be referred to as named
properties of the - document.forms collection, and named form
controls may be referred to as named properties of the form's
elements collection:

I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms['..'].elements['..']

Do not let terrible MS asp.net terminology sip into this FAQ.
"Control" is terminology from the W3C HTML specification, referring to
TEXTAREA, INPUT, SELECT and BUTTON elements (and hypothetically OBJECT
elements). Previously it has been suggested that "element" may be
confusing because all HTML elements are represented in the DOM with
elements implementing the Element interface.

Richard.

Feb 19 '07 #3

P: n/a
Richard Cornford wrote on 19 feb 2007 in comp.lang.javascript:
On Feb 19, 9:55 am, "Evertjan." <exjxw.hannivo...@interxnl.netwrote:
>FAQ server wrote on 19 feb 2007 in comp.lang.javascript:
>>In HTML documents, named forms may be referred to as named
properties of the - document.forms collection, and named form
controls may be referred to as named properties of the form's
elements collection:

I would not use the "form controls" but "form elements".

After all the DOM uses:

document.forms['..'].elements['..']

Do not let terrible MS asp.net terminology sip into this FAQ.

"Control" is terminology from the W3C HTML specification, referring to
TEXTAREA, INPUT, SELECT and BUTTON elements (and hypothetically OBJECT
elements). Previously it has been suggested that "element" may be
confusing because all HTML elements are represented in the DOM with
elements implementing the Element interface.
I would have objected if I had known.

Perhaps "input element"?

Throwing a switch perhaps,
but entering or dropping text does not satisfy
my understanding of controlling.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Feb 19 '07 #4

This discussion thread is closed

Replies have been disabled for this discussion.