This is a discussion on How do I get the value of a form control? within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi all....... How do I get the value of a form control? Thanks & Regards itbarota....
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi all..... 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:- Referencing Forms and Form Controls Third Exception: File Inputs where most current browsers do not allow the reading of type="file" input elements in a way that is useful. |
| |||
| <html> <head> <title>Selecting Text Upon Focus</title> </head> <body> <form name="form1" method="POST"> <h2>Selecting Text Upon Focus</h2> <p>Username:<br> <input type=text size=25 maxlength=256 name="Username" onFocus="this.select()"><br> Browser used:<br> <input type=text size=25 maxlength=256 name="Browser" onFocus="this.select()"><br> Email address: <strong> <br> </strong> <input type=text size=25 maxlength=256 name="EmailAddress"onFocus="this.select()"> </p> <h2> <input type=submit value="Register"> <input type=reset value="Clear"> </h2> </form> </body> </html> |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Date/time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 02-06-2008 09:16 PM |
| Date/Time stamp a form field as the form is submitted | itbarota | HTML, CSS and Javascript Coding Techniques | 2 | 01-17-2008 07:47 PM |
| How can I clear the form field values after the user has submitted the form for clien | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 11-01-2007 10:39 PM |
| How can I pass a hidden value to a form and submit that form when a text link is clic | itbarota | HTML, CSS and Javascript Coding Techniques | 1 | 10-17-2007 07:07 AM |
| use of Custom Control and User Control? | a.deeban | ASP and ASP.NET Programming | 1 | 08-20-2007 07:25 AM |