Cancel the Submit if vbscript function is true

Posted on 1999-06-28
Medium Priority
Last Modified: 2013-12-25
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")'>
Question by:streka
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
LVL 18

Expert Comment

ID: 1863557
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
         { .....  
      Alert "FlightDates must be in the date format"
   Alert "FlightDates must be in the date format"

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

LVL 18

Expert Comment

ID: 1863558
Sorry, left a few things out...

<Script language="vbscript" >
Sub CheckDate_OnClick
       dim beg1
       dim end1

       If beg1 Then
          If end1 Then
                Alert "Good Date"
             Alert "FlightDates must be in the date format"
                   End if
          Alert "FlightDates must be in the date format"
End if
End Sub

<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">


Author Comment

ID: 1863559
Yes, but how do I cancel the submit??? It would have to be a Submit button though.
Learn how to optimize MySQL for your business need

With the increasing importance of apps & networks in both business & personal interconnections, perfor. has become one of the key metrics of successful communication. This ebook is a hands-on business-case-driven guide to understanding MySQL query parameter tuning & database perf


Expert Comment

ID: 1863560
No leave it as a regular button.

But where he has

Alert "Good Date"

instead put


I just added a similar comment to your other question.

Accepted Solution

mjpieters earned 240 total points
ID: 1863561
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

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

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


Author Comment

ID: 1863562
yeah, that would work. Thanks.

Featured Post

Quiz: What Do These Organizations Have In Common?

Hint: Their teams ended up taking quizzes, too.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
Any person in technology especially those working for big companies should at least know about the basics of web accessibility. Believe it or not there are even laws in place that require businesses to provide such means for the disabled and aging p…
The is a quite short video tutorial. In this video, I'm going to show you how to create self-host WordPress blog with free hosting service.
Suggested Courses

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question