Abstract This is the second part of a series of articles on HTML forms processing in JavaScript. We have already reviewed how to create HTML forms and how to pass a form to a JavaScript function for validation. See my last article if you are new to this topic. Today we will see two HTML form objects: text boxes and passwords. So, lets start the work!
Text Boxes Text Boxes are used to get input in text form, like userid and addressing information, etc. In JavaScript a text box object supports several properties; the most important of which is "value". Suppose you have a text box named email which contains the text ali_bhai@yahoo.com. You can access this text (or value) by using email.value in a JavaScript function. This value property is a string in itself and therefore supports all string properties like length and methods like toUpperCase(). Suppose you want to determine the length of the email address entered by the user; you can do so by writing email.value.length. Following example will clarify the things.
<html> <body> </body>
<head>
<title>HTML Form Processing</title>
<script languague="JavaScript">
<!--hiding from old broswers
function check_form (myForm)
{
len = myForm.email.value.length;
alert ("Your email address is " + len + " characters long");
}
// -->
</script>
</head>
<form name="survey">
Enter you email <input type="text" name="email">
<input type="button" value="Check Size" onClick="check_form(survey)">
</form>
</html>
Go To Page: 1 2