ENOTES

form validation in javascript

access_time Apr 09, 2022 remove_red_eye 10010

Once the client or user entered all the necessary data and  press the submit button then all the data entered by the client must be correct and valid. Thus, form validation is the mechanism which allows client to enter only the correct information which can be send to the server. JavaScript provides easy method for form validation at client side. Forma validation can be done in two ways: Basic validation which checks whether all the required fields are filled properly or not kept empty whereas, Data Format validation check whether the data entered into the form field are logically correct.

Basic form validation in JavaScript

<HTML>
<HEAD><TITLE>Form Validation</TITLE></HEAD>
<BODY>
<FORM>
<INPUT type = "text" id = "user">
<INPUT type = "password" id = "pass">
<INPUT type = "submit" onclick = "valid( )">
</FORM>
          
<SCRIPT>       
   
    function valid()
    {
        var user = document.getElementById("user").value;
        var pass = document.getElementById("pass").value;
        if(user == "" || pass == "")
        {
         alert("Please!! Fill up the form");
        }
    }

</SCRIPT>
</BODY>
</HTML>

Click here for Adding two number in JavaScript.

Factorial of a given number using JavaScript