www.webdeveloper.com
Results 1 to 3 of 3

Thread: Keep process stopped when alert 'OK' pressed

  1. #1
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043

    Keep process stopped when alert 'OK' pressed

    This function checks dates for validitity, with return if all dates are correct:

    Code:
    function doDateCheck(from, to) {
    if (Date.parse(from.value) <= Date.parse(to.value)) {
    return;
    }
    else {
    if (from.value == "" || to.value == "")
    alert("Both dates must be entered.");
    else
    alert("To date must occur after the from date.");
    }
    }
    In the related form, the submit button is configured like so:

    Code:
    <input type="Submit" name="Submit" onClick="doDateCheck(this.form.from, this.form.to);" value="Send">
    When I attempt to submit the form with invalid dates, this picks up the failures, but when the OK button of the alert box is clicked, the form then posts as if the values had been correct.

    I want the precess to stop until the input dates have been corrected to an acceptable value, and the submit button is re-pressed. How to I go about that?

  2. #2
    Join Date
    May 2005
    Location
    Dirty Jersey
    Posts
    1,401

  3. #3
    Join Date
    Jun 2005
    Location
    United Kingdom
    Posts
    1,043
    Thank you for coming back on this.

    So, as I understand it, if the function is re-written like this:
    Code:
    function doDateCheck(from, to) {
    if (Date.parse(from.value) <= Date.parse(to.value)) {
    return true;
    }
    else {
    if (from.value == "" || to.value == "")
    alert("Both dates must be entered.");
    return false;
    else
    alert("To date must occur after the from date.");
    return false;
    }
    }
    and the form is coded:

    Code:
    <form action="feedback.php" method="post" onSubmit="return doDateCheck(this.form.from, this.form.to)">
    <pre>
    From date <input type=text name=from onBlur="checkdate(this)" size=11 maxlength=11>
    To date <input type=text name=to onBlur="checkdate(this)" size=11 maxlength=11>
    
    <input type="Submit" name="Submit" value="Send">
    </pre>
    </form>
    All should now be well. Unfortunately, entering a false date is now ignored - so clearly I am missing a trick. I'd be grateful for a further steer on this.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles