Prev: asp
Next: Dateiendung Pr�fung
From: FAQ server on 5 Feb 2010 19:00 ----------------------------------------------------------------------- FAQ Topic - How do I get the value of a form control? ----------------------------------------------------------------------- In HTML documents, a form may be referred to as a property of the ` document.forms ` collection, either by its ordinal index or by name (if the ` form ` has a name). A ` form `'s controls may be similarly referenced from its ` elements ` collection: var frm = document.forms[0]; var contrl = frm.elements["elementname"]; Once a reference to a control is obtained, its (string) ` value ` property can be read:- var value = control.value; value = +control.value; //string to number. 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 = control.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://jibbering.com/faq/faq_notes/form_access.html http://jibbering.com/faq/names/ Third Exception: File inputs. Most current browsers do not allow reading of ` type="file" ` input elements in a way that is useful. The complete comp.lang.javascript FAQ is at http://jibbering.com/faq/ -- The sendings of these daily posts are proficiently hosted by http://www.pair.com.
From: Dr J R Stockton on 1 Mar 2010 15:36 In comp.lang.javascript message <4b6cb109$0$271$14726298(a)news.sunsite.dk >, Sat, 6 Feb 2010 00:00:02, FAQ server <javascript(a)dotinternet.be> posted: >In HTML documents, a form may be referred to as a property of the >` document.forms ` collection, either by its ordinal index or by name >(if the ` form ` has a name). A ` form `'s controls may be similarly referenced >from its ` elements ` collection: The beginning of the second sentence is ugly, on Web and in News, since there is a font change in the middle of a word. Easily fixed : change to "Controls in a ` form ` may be ..." which is only one character longer. Likewise elsewhere, if applicable. -- (c) John Stockton, nr London UK. replyYYWW merlyn demon co uk Turnpike 6.05. 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 precede replies. Snip well. Write clearly. Mail no News.
|
Pages: 1 Prev: asp Next: Dateiendung Pr�fung |