#1
  1. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    2
    Rep Power
    0

    Question JavaScript: Form field error checking


    I have a page which contains an HTML form. When the user clicks the submit button, I want to check to make sure that all of the form fields have been filled in. I also want to check that certain fields contain no letters, that certain fields contain no numbers, and that the email field is in the form a@b.c If there is a problem, a box should pop up asking the user to fix the problems. If everything is fine, things should continue normally (as if there was no javascript). How can I do this?
  2. #2
  3. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2001
    Location
    Seattle, WA
    Posts
    18
    Rep Power
    0

    Cool Try this . .


    Go to this link and do a find in the page for "validation". There are MANY examples of how to do it from dates, to characters, to email addresses. Takes a minute to load, but well worth it as a reference and to "code reuse". ;-) It's free.

    Rachel


    http://javascript.internet.com/maste...ster-list.html
  4. #3
  5. No Profile Picture
    Junior Member
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2001
    Posts
    2
    Rep Power
    0
    Very helpful, thanks!
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Apr 2013
    Posts
    31
    Rep Power
    2
    I got the validation working thanks to the link above but would like to expand what it checks for and am having some trouble doing this.

    It currently checks the values are within a set range and display particular error messages if not (depending on its too high, too low, or empty). I would also like it to check that the value is actually a number. I tried using isNaN but it's not working.

    Also, I would like the calculation to occur ONLY if all the fields pass. I tried using an if statement to check if the function is true (and the validate function returns true or false based on the result) but it doesn't work.

    Here are a link to the files
    http://tiger.towson.edu/~tbaldw2/loan_calculator/LoanCalc.html
    http://tiger.towson.edu/~tbaldw2/loan_calculator/LoanCalc.js
    (working files)

    http://tiger.towson.edu/~tbaldw2/loan_calculator/LoanCalc1.html
    http://tiger.towson.edu/~tbaldw2/loan_calculator/LoanCalc1.js (with the non-working changes)

IMN logo majestic logo threadwatch logo seochat tools logo