Link to home
Start Free TrialLog in
Avatar of streka
streka

asked on

Cancel the Submit if vbscript function is true

I am validating dates with vbscript on submit How do I cancel the submit if the functon is true?

<INPUT TYPE="SUBMIT" NAME="Action" VALUE="<%=SUBMITVALUE%>" LANGUAGE="VBScript" ONCLICK='If Not IsDate(BegFlightDate.value) Or Not IsDate(EndFlightDate.value) Then MsgBox("FlightDates must be in the date format")'>
Avatar of Mark Franz
Mark Franz
Flag of United States of America image

Use the IsDate() function;

Sub CheckDate_OnClick
dim beg=IsDate(BegFlightDate.value)
dim end=IsDate(EndFlightDate.value)

If beg Then
   If end Then
         Function Submit_Values
         { .....  
          }
   else
      Alert "FlightDates must be in the date format"
else
   Alert "FlightDates must be in the date format"

...
<form>
<input type="button" name="CheckDate" value="Check Date">
</form>

Sorry, left a few things out...

<html>
<head>
      <title>Untitled</title>
<Script language="vbscript" >
Sub CheckDate_OnClick
       dim beg1
         beg1=(IsDate(Document.date1.begdate1.Value))
       dim end1
         end1=IsDate(Document.date1.end1date1.Value)

       If beg1 Then
          If end1 Then
                Alert "Good Date"
                        Else
             Alert "FlightDates must be in the date format"
                   End if
       else
          Alert "FlightDates must be in the date format"
End if
End Sub
</script>
</head>

<body>
<form name="date1">
<input type="text" name="begdate1" size="10">Begin Date <br>
<input type="text" name="end1date1" size="10">End Date <br>
<input type="button" name="CheckDate" value="Check Date">
</form>
</body>
</html>

Avatar of streka
streka

ASKER

Yes, but how do I cancel the submit??? It would have to be a Submit button though.
No leave it as a regular button.

But where he has

Alert "Good Date"


instead put

date1.submit


I just added a similar comment to your other question.
ASKER CERTIFIED SOLUTION
Avatar of mjpieters
mjpieters

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of streka

ASKER

yeah, that would work. Thanks.