Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <form name="frm" onClick="return formValid(this)">
- <table>
- <tr>
- <td>Form Validation By Switch Case</td>
- </tr>
- <tr>
- <td>
- <input type="text" name="name" placeholder="Name"/>
- <span id="showTextName"></span>
- </td>
- </tr>
- <tr>
- <td>
- <input type="text" name="email" placeholder="Email"/>
- <span id="showTextEmail"></span>
- </td>
- </tr>
- <tr>
- <td>
- <input type="text" name="password"/>
- <span id="showTextPass"></span>
- </td>
- </tr>
- <tr>
- <td>
- <input type="submit" value="submit"/>
- </td>
- </tr>
- </table>
- </form>
- <script>
- function formValid(process){
- with(document.frm) // short in method of form name in javascript
- switch(process){
- case document.frm:
- if(name.value == ""){
- document.getElementById('showTextName').innerHTML = "Please Enter Your Name";
- name.select();
- return false;
- }
- if(email.value == ""){
- document.getElementById('showTextEmail').innerHTML = "Please Enter Your Email";
- email.select();
- return false;
- }
- if(password.value == ""){
- document.getElementById('showTextPass').innerHTML = "Please Enter Your Password";
- password.select();
- return false;
- }
- break;
- }
- }
- </script>
- <style type="text/css">
- #showTextName,#showTextEmail,#showTextPass{
- color:red;
- }
- </style>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement