Required Fields

 
 
The function below checks if a required field has been left empty. If the required field is blank, an alert box alerts a message and the function returns false. If a value is entered, the function returns true (means that data is OK):
 
 
  1. <html>

  2. <head>

  3. <script type="text/javascript">

  4. function validate_required(field,alerttxt)

  5. {

  6. with (field)

  7. {

  8. if (value==null||value=="")

  9.   {alert(alerttxt);return false;}

  10. else {return true}

  11. }

  12. }

  13.  

  14. function validate_form(thisform)

  15. {

  16. with (thisform)

  17. {

  18. if (validate_required(email,"Email must be filled out!")==false)

  19.   {email.focus();return false;}

  20. }

  21. }

  22. </script>

  23. </head>

  24.  

  25. <body>

  26. <form action="submitpage.htm"

  27. onsubmit="return validate_form(this)"

  28. method="post">

  29. Email: <input type="text" name="email" size="30">

  30. <input type="submit" value="Submit">

  31. </form>

  32. </body>

  33.  

  34. </html>
 
Copy to Clipboard      Download code as Text Format
 
  Date entered : 25th Mar 2008
  Rating : No Rating
  Accessed  :  1585
  Submitted by :  goldeekhan
 
   Add Comment  Printer friendly
   View All Comments  Email to a friend
   Add to my Favourites Download PDF version
   Rating  
 
                 Click each image to add
this page to each site.
 
 
 
Comments Available

    No comment available at the moment.Be the first one to make a comment

 
Related JavaScript Source Codes
  • Spring
  • Wraps a string to a given number of characters using a string break character
  • Uppercase the first character of each word in a string
  • Make a string's first character uppercase
  • Strip whitespace (or other characters) from the beginning and end of a string

  • Copyright © 2010 VisualBuilder. All rights reserved