Checking non empty field
Often, situations arise when a user should fill a single or more than one field in an HTML form before they submit it. You can write a JavaScript form validation script to check whether the required field(s) in the HTML form is blank or not.
The following function can be used to check whether the user has entered anything in a given field. Blank fields indicate two kinds of values. A zero-length string or a NULL value.
Javascript function to check whether a field is empty or not
At first the function required() will accept the HTML input value through inputtx parameter. After that length property of string, object is used to get the length of the said parameter. If the length of value.inputtx is 0 then it returns false otherwise true. Here is the complete web document.
Flowchart:
HTML Code
JavaScript Code
CSS Code
Another function to check whether a field is empty
In the above function background color of the input field will be yellow if the user input a blank field otherwise the background color will be white.
Flowchart:
No comments:
Post a Comment