Jump to content

Simple JavaScript Validator

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
4 replies to this topic

#1
Blue Indian

Blue Indian

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
I am trying to use client-side validation with javascript. I feel like I am on the right track, but for some reason this code is not working.

My page is found at:
Simple Form Validation

All the source is there if you hit view source.

#2
cdg10620

cdg10620

    Programming Expert

  • Members
  • PipPipPipPipPipPip
  • 389 posts
Load this up in Firefox and debug it using an AddOn called Firebug. You're getting an error on line 20 in your .js file that says an object is expected. Also, you can use JSLint to validate your javascript code and quickly identify any errors. One thing I saw is that you're using "=" to evaluate equality instead of "===" which is a no no. If you use the equals operator like this "=" your attempting to assign a value and not evaluate if two values are equal.

If you need any more help let me know.

BTW. this is my 300th post. FTW!
-CDG10620
Software Developer

#3
dbug

dbug

    Programmer

  • Members
  • PipPipPipPip
  • 155 posts
There are some problems...

  • IsNaN should be isNaN (first 'i' must be lowercase)
  • innerText is not supported by some browsers. It's better to use innerHTML.
  • The age check should only be done if the name is correct or don't change the value of isValid if it was false (actually, if you write a wrong name but a correct age, it will show the last message 'You entered ...')
With these changes it should work

#4
gokuajmes

gokuajmes

    Programming God

  • Members
  • PipPipPipPipPipPipPip
  • 518 posts
Well it works fine for me :D

#5
Blue Indian

Blue Indian

    Learning Programmer

  • Members
  • PipPipPip
  • 67 posts
Yes, I fixed it with the help of the previous suggestions.

Thanks guys!