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

    Join Date
    Sep 2000
    Location
    Iowa
    Posts
    22
    Rep Power
    0

    JavaScript validate number question


    I'm trying to validate a form using javascript and need to make sure that the class year field is both not blank, and is or is between the years 1903 and 2004.

    I have:

    else if (form.classyear.value == "") || ((form.classyear.value >=1903) && (form.classyear.value <= 2004))

    {
    alert("Please enter a valid four digit class year");
    form.classyear.focus();
    }

    The else if (form.classyear.value == "") part works by itself, so I'm guessing it's something in my comparison as this produces a syntax error. Any help is appreciate. Thanks.
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Feb 2003
    Location
    Iasi, Romania
    Posts
    20
    Rep Power
    0

    hi


    Hi,

    lets put this in plain English:
    Else if "value of classyear is empty" OR "the value of classyear is bigger or equal with 1903 AND the value of classyear is smaller or equal with 2004" pop-up alert box. My guesses are that you have a syntax error in your javascript code. Try this one:

    Code:
    else if ((form.classyear.value == "") || ((form.classyear.value >=1903) && (form.classyear.value <= 2004)))
    {
    alert("Please enter a valid four digit class year");
    form.classyear.focus();
    }
    Can you tell me the result please?

    Stefan
    PS. What browser name/version are you useing to render your page?
  4. #3
  5. No Profile Picture
    Devshed Newbie (0 - 499 posts)

    Join Date
    Sep 2000
    Location
    Iowa
    Posts
    22
    Rep Power
    0
    I figured out that the problem was that I needed another or rather than an and to make it do what I was looking for. Thanks for offering the help though.

IMN logo majestic logo threadwatch logo seochat tools logo