onsubmit

  • Thread starter How to control onsumbit in VBScript
  • Start date
H

How to control onsumbit in VBScript

Hi,
Is it possiable to control the onsubmit function in VBScript?

For example, I have a form with only one check box. I like to verify the
check box on checked before to send the email out. If the check box do not
check, display the message to user. The verify function will like following:

Java Script
function ValidateForm(chkbx)
{

if(chkbx.checked == true)
{
return true
}
else
{
window.alert("Please check on the check box.");
return false;
}
}

Then I can use the onsubmit="return ValidateContactForm();" to make it work
(The email send out or not is controled by function return false or true).

But in VBScript, I have to write the function as following:
Public function ValidateForm()
if chkbx.checked = true then
ValidateForm = true
else
ValidateForm = false
end if
end function
Then I only can use the onsubmit="ValidateContactForm()" to make it work
(The email will send out whatever function return false or true).
I get compile error when I try to following cases:
onsubmit="retun ValidateContactForm()"
onsubmit="ValidateContactForm() = true"

Please help me to find where I am wrong.

Thanks,
Xiao
 
J

Jim Buyens

How about:

<input type="button" value="Submit" name="btnSub"
onclick="if chkbx.checked then forms(0).submit()">

Jim Buyens
Microsoft MVP
http://www.interlacken.com
Author of:
o--> Microsoft Visual Web Developer 2005 Express Edition: Build a Web Site
Now!
o--> Microsoft Office FrontPage 2003 Inside Out
o--> Microsoft Windows SharePoint Services Inside Out
o--> Faster Smarter Beginning Programming
 
P

p c

You can either use vbscript or javascript. However, only IE can run
vbscript. And you would want to incorpate the validating in a single
function.

Your options are:
1. Vaildate all feiels on the cliint usiing javascript(what you are
trying to do). But you would need to combine all the validation checks
in a single fucntion used by the onsubmit event. (You can incorporate
calls to other javascript functions from that function if you want to.)

2. Validate on the server with scrpt (vbscipt or j'script for ASP, PHP
etc for tother servers)

3. Validate on the server wiht FP if the server has FPSE installed.

For option 1 for examples how to do it, see the tutorial at:
http://www.webthang.co.uk/tuts/tuts_html/form_validation/validate.asp

Or Google for plenry of sampels for "Form Validation With JavaScript"
without quotes.

...PC
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top