Results 1 to 4 of 4

Thread: Help With Validation on Jason's Date Input Calendar

  1. #1
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Help With Validation on Jason's Date Input Calendar

    Hi,
    I'm using Jason's Date Input Calendar, within a Form, to display the current date and to allow the user to select a 'response by' date. I want the validation to alert the user if the second date they've selected is in the past.

    The following code achieves this, but upon clicking 'ok' to the pop-up alert box - the Form posts regardless.

    Can anyone help please?

    The basic code is as follows:

    <html>
    <head>
    <script type="text/javascript" src="calendarDateInput.js">
    </script>
    </head>

    <body>

    <script type="text/javascript">
    function validateTheDate() {
    var Today = new Date();
    if (Response_Requested_By_Object.picked.date < Today) alert('Cannot select a date in the past.');
    else if (Response_Requested_By_Object.picked.yearValue > 2020) alert('Cannot select dates beyond 2020.');
    }
    </script>


    <form method="post" action="../mailing.asp" Name="Form" onSubmit="validateTheDate();">

    <table>
    <tr>
    <td colspan="2">Date Requested</td>
    <td><script>DateInput('CCN_Request_Date', true, 'DD-MON-YYYY')</script></td>
    </tr>
    <tr>
    <td colspan="2">Response Requested By</td>
    <td><script>DateInput('Response_Requested_By',true, 'DD-MON-YYYY')</script></td>
    </tr>
    </table>

    <table>
    <td><input type="Submit" value="Finish!"></td>
    </table>
    </form>
    </body>
    </html>

  2. #2
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    When calling a function from the onSubmit event-handler of a form, if you don't want the form to submit, you must return FALSE from that function.

    So, you'd want to change the following:

    1) Put the "return" keyword in front of your onSubmit function call:

    <form ... onSubmit="return validateTheDate()">

    2) Make sure to return false when they screw up the date:

    function validateTheDate() {
    var dateOK = false;
    var Today = new Date();
    if (Response_Requested_By_Object.picked.date < Today) alert('Cannot select a date in the past.');
    else if (Response_Requested_By_Object.picked.yearValue > 2020) alert('Cannot select dates beyond 2020.');
    else dateOK = true;
    return dateOK;
    }

  3. #3
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Nice one.

    All sorted... and it makes sense!!

    Good looking script - Thanks for your help!!

  4. #4
    Join Date
    Jul 2006
    Posts
    10
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Hi
    It worked for me yesteday. But today when I again started debugging the project it is not working. What can be the case. Will you please help me?
    Regards
    Mahathi.
    Last edited by mahathi; 07-25-2006 at 05:15 AM.

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
  •