• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 4659
  • Last Modified:

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")'>
0
streka
Asked:
streka
1 Solution
 
mgfranzCommented:
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>

0
 
mgfranzCommented:
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>

0
 
strekaAuthor Commented:
Yes, but how do I cancel the submit??? It would have to be a Submit button though.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
mayhewCommented:
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.
0
 
mjpietersCommented:
You cancel the submit event by returning a false value from Javascript, or by setting the returnValue property of the window.event object to false.

To cancel the submitting of a form, you probably would do better using the onSubmit property of the FORM tag:

<FORM .... onSubmit="window.event.returnValue = False">

If you want to validate your form, and then want to decide wether or not to allow submission, you would do better defining a special script block for handling the event:

<SCRIPT FOR=OrderForm EVENT="onclick()" LANGUAGE="VBScript">
If Not IsDate(BegFlightDate.value) Or Not IsDate(EndFlightDate.value) Then
    MsgBox("FlightDates must be in the date format")
    window.event.returnValue = False
End If
</SCRIPT>

Name your FORM element OrderForm:
<FORM .... ID=OrderForm>

and don't specify any events on your FORM or Submit buttons.

0
 
strekaAuthor Commented:
yeah, that would work. Thanks.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now