|
-
Mar 18th, 2002, 02:00 PM
#1
Thread Starter
Member
Stopping a form from submitting with VBSCript
I am trying to run a Validation function that is called when the submit button is clicked. The function checks the defined restrictions on the form, and if there is an error found, sets the status variable to 1. If there are not errors, the Status variable stays a 0. this is the next if statement I have:
IF Status = "0" THEN
document.form.submit()
ELSE
return false
END IF
the return false should stop the form from submitting. This is a JavaScript function, but I thought I was the same in VBScript, but unfortunately, the form still dispalys the errors, but also submits. Does anyone know how to keep a form from not submitting?
Steve
-
Mar 18th, 2002, 02:22 PM
#2
Frenzied Member
First of all, is the button's type 'submit' or 'button'? If it is of type submit, I doubt that your form validation is even working. You should have the button's type be 'button' and call the JavaScript function from the button's OnClick event.
seoptimizer2001
VB 6.0, VC++, VI, ASP, JavaScript, HTML,
Perl, XML, SQL Server 2000
If God had intended us to drink beer, He would have given us stomachs.
Please use the [code] and [vbcode] tags in your posts!
If you don't know how to use them please go HERE!

-
Mar 18th, 2002, 02:27 PM
#3
Frenzied Member
Also your if statement is incorrect in javascript. Another thing to consider is what type of value has been passed to and stored in Status? You are doing a string comparison, if you passed a number to the variable, this would also cause your if ... then not to work properly.
Code:
if (Status=="0")
{
document.form.submit() ;
return true;
}
else
{
return false;
seoptimizer2001
VB 6.0, VC++, VI, ASP, JavaScript, HTML,
Perl, XML, SQL Server 2000
If God had intended us to drink beer, He would have given us stomachs.
Please use the [code] and [vbcode] tags in your posts!
If you don't know how to use them please go HERE!

-
Mar 18th, 2002, 02:44 PM
#4
Thread Starter
Member
No, my validation if statements are working fine. I receive every message when I should. I was using the onclick function and the problem was that when you clicked the enter key, the form was submitting without hitting the button hense, no validation. I had to use the onsubmit. and you are right, my if statements are not Javascript, but VBScript. I would like to stay with VBScript so all I am asking is if someone knows the correct return false statement in VBScript. Thanks though.
Steve
-
Mar 18th, 2002, 03:20 PM
#5
Originally posted by warker
. I would like to stay with VBScript so all I am asking is if someone knows the correct return false statement in VBScript. Thanks though.
Steve
Hi Steve,
You shouldnt use vbscript on client side, but since you are adament here is how you can validate a form using VBScript.
Hope this helps
Danial
VB Code:
<HTML>
<HEAD>
<TITLE></TITLE>
<script language=vbscript>
function validate()
if test.text1.value="" then
msgbox "Please enter a value"
Window.event.returnValue = false
end if
end function
</script>
</HEAD>
<Form name=test onsubmit="validate()">
<input type=text name=text1>
<input type=submit>
</BODY>
</HTML>
[VBF RSS Feed]
There is a great war coming. Are you sure you are on the right side? Atleast I have chosen a side.
If I have been helpful, Please Rate my Post. Thanks.
This post was powered by : 
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|