Results 1 to 6 of 6

Thread: Validate a specific date range

  1. #1
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question Validate a specific date range

    Hello,
    I would like to have a specific date range in years entered into a text box and if anything else is entered a pop up alert would appear. The date range would be from 1912 to 2002. Any help with this would be greatly appreciated.

    This is the Javascript I am trying to use:

    Code:
    <script type="text/javascript">
    function checkDate(theForm) 
    year=document.getElementById('YearBorn').value;
    if(year<1912 || year>2002)
    {
      alert("registration is restricted to those born between 1912 to 2002");
      return false;
      else {
      return true;
    }
    }
    </script>

    I have included this code in the Additional Attributes:

    Code:
    onblur="return checkDate(this);"

  2. #2
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    So what's the problem that you're experiencing with this code?

  3. #3
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    First Thank you for asking.
    The code does not validate and put up an alert if the a date out of range is entered.
    The form is located here http://www.rocpinions.com/main-form.html and the question is at the top of page 2 of the multi form

    Thanks
    DeZiner

  4. #4
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    Try this instead -
    <script type="text/javascript">
    function checkDate(theForm) {
    year=document.getElementById('YearBorn').value;
    if(year<1912 || year>2002)
    {
    alert("registration is restricted to those born between 1912 to 2002");
    return false;
    else {
    return true;
    }
    }
    Also you're passing a paramater (theForm) but not using it.
    </script>

  5. #5
    Join Date
    Oct 2010
    Location
    Lakewood, New York
    Posts
    7
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Question

    ok I still can't get this working I am not a coder so this is giving me grief. How do I call this function? I am using

    onblur="return checkDate(this);"

    is that correct?

  6. #6
    Join Date
    Mar 2011
    Location
    N 11 19' 0.0012 E 142 15' 0
    Posts
    1,509
    Thanks
    41
    Thanked 89 Times in 88 Posts
    Blog Entries
    3

    Default

    yep, just remove the old checkDate() function from your page and put in the new one. The only difference is you're missing a paranthesis {

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
  •