SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    javascript validation

    Hi,

    I have a question. Suppose I have a form with ten fields on it text boxes, radio buttons, and supose check boxes.

    Now I need to make sure everthing is filled. In my Javascript

    instead of if statments for each

    if (documnet.getelementBy id('name')== "")

    can i do, some sort of a for loop and validate all the fields?

    Thanks

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Yes, you can loop through the form's elements[] collection with a for loop. You may need to check the type property of each of the form controls.

    Don't forget that you must validate on the server, even if you validate with JavaScript too.

    http://www.javascriptkit.com/jsref/
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Wizard
    Join Date
    Dec 2004
    Location
    At My Desk!!
    Posts
    1,642
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Kravvitz
    Don't forget that you must validate on the server, even if you validate with JavaScript too.
    Exactly, the client can easily turn JavaScript off and therefore not have to validate anything
    "Am I the only one doing ASP.NET in Delphi(Pascal)?"

  4. #4
    SitePoint Enthusiast
    Join Date
    Oct 2006
    Posts
    55
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i could not find any example over the net, how to loop through elemenst of form and validate ........

  5. #5
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Did you look at the site I linked to?
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •