473,387 Members | 1,624 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,387 software developers and data experts.

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

-----------------------------------------------------------------------
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
3 2937
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

8
by: Zlatko Matiæ | last post by:
There is a form (single form) and a combobox. I want that current record of the form is adjusted according to selected value in the combobox. Cuurrent record should be the same as the value in the...
109
by: MSG | last post by:
Michel Bardiaux <michel.bardiaux@peaktime.be> wrote in message news:<G4idnfgZ0ZfCWbrdRVn2jQ@giganews.com>... > Mark Shelor wrote: > > > > > OK, Sidney, I am considering it. I can certainly...
5
by: Nathan Sokalski | last post by:
I have a user control that contains three variables which are accessed through public properties. They are declared immediately below the "Web Form Designer Generated Code" section. Every time an...
13
by: Deano | last post by:
Apparently you can only do this with one value i.e Call MyAssetLocationZoom(Me!txtLocation, "Amend data") This runs; Public Sub MyAssetLocationZoom(ctl As Control, formName As String) On...
25
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does parseInt('09') give an error? ----------------------------------------------------------------------- ...
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? -----------------------------------------------------------------------...
19
by: Dave | last post by:
If Iwant to check if dataset1.SelectQuery1.column1 == System.DBNull.Value. How do I do this? What I wrote above will give an error. -- L. A. Jones
2
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - Why does 1+1 equal 11? or How do I convert a string to a number?...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
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...

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.