HTML 5 REQUIRED FIELD VALIDATOR WITHOUT USING JAVASCRIPT

Before the user submits any forms, it is very necessary to check whether all the required fields are filled or not. If the programer fails to implement required field validator in HTML forms, lazy users will skip all the necessary fields and so it leads to get only minimal details. 

Required field validation using Javascript 

So, initially programmers used javascript to perform this operation. Later they used jquery. But now in HTML 5, required field validation can be performed without the help of any supporting languages. For example, to validate username 

<script>
function validateForm()
{
var textbox1 = document.forms["form1"]["user_name"].value; 
    
if (textbox1 == null || textbox1 == "")           
{
alert("User name must be filled out");
return false;
}
}
</script>

<form name="form1" action="" onsubmit="return validateForm()"
>
<input type="text" name="user_name"/>
</form>



What is the syntax for HTML required field validator:

required

Sample Program:

Output:

Text Box1 :
Password :
Select Menu :

Click Here to get -- > HTML Tutorials by Studentsblog100

Previous
Next Post »