?
Solved

Cancel the Submit if vbscript function is true

Posted on 1999-06-28
6
Medium Priority
?
4,643 Views
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")'>
0
Comment
Question by:streka
[X]
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
6 Comments
 
LVL 18

Expert Comment

by:mgfranz
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
         { .....  
          }
   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
 
LVL 18

Expert Comment

by:mgfranz
ID: 1863558
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
 

Author Comment

by:streka
ID: 1863559
Yes, but how do I cancel the submit??? It would have to be a Submit button though.
0
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

 
LVL 5

Expert Comment

by:mayhew
ID: 1863560
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
 
LVL 1

Accepted Solution

by:
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
</SCRIPT>

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

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

0
 

Author Comment

by:streka
ID: 1863562
yeah, that would work. Thanks.
0

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