

Now that the text box value is accessed and retrieved, it must be stored. The line document.getElementById("firstname").value accesses the text box with an id of firstname and retrieves the value which the user has entered into
#INPUT AND GETOUTPUT FOR A TEXTBAR ON JS CODE#
To extract the information which a user enters into the text fields using Javascript, the Javascript code to do would be: In this form, the unique id attributes are again firstname and lastname. This is how Javascript will knowĮxactly which text box it is referencing. Each text box which you use, even if you have 50 text boxes for a form, must each have a unique id attribute. This is a very important attribute because this is the attribute which Javascript will use in order In theĬases of these 2 text boxes, the id attributes are firstname and lastname.

The only other attribute which each text box needs is the id attribute. Setting the input attribute to text allows means the input form field will be a text box. The above HTML code is how we create text boxes, such as those seen in standard web forms, where a user can input information into. For the 2 text boxes shown in our example above, the HTML code to create them is: Once a user fills out the text fields of a form, how can we extract this information using Javascript so that we can processīefore we discuss the Javascript to extract the information from a web form, we first have to go over the HTML code whichĬreates the text box. It doesn't extract any information which the user enters which we can use for any practical purposes. However, you can see with the above form that once entering information and clicking the submit button, the form doesn't doĪnything meaningful. Below is an example of a web form which asks a user for his/her first name and last name:
