Validate text boxes with vbscript
I'm trying to make a 'Create User Account' page with asp and vb script.
I want to validate the text box entries before passing to the next page.
I searched the forums and tried to use the most promissing code I could find, but it's not working.
It just goes to the next page as soon as you click the submit button.
Can anyone help?
Code:
<HTML>
<HEAD>
<title>New Account</title>
<SCRIPT Language="vbscript">
function Validate
Msgbox "Just a test pop-up !!!"
If (document.form.UserName.value = "" or _
document.form.Password.value = "" or _
document.form.Confirm.value = "" ) Then
Msgbox "Fill in text box !!!"
Validate = false
Else
Validate = true
End If
end function
</SCRIPT>
</HEAD>
<BODY>
<CENTER>
<BR>
<BR>
<FORM NAME="Logn" METHOD="post" ACTION="index.shtml">
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="7" WIDTH="250" BGCOLOR="#6B656B">
<TR>
<TD>
<H3>Create a New Account</H3>
User Name:<BR>
<INPUT TYPE="text" NAME="UserName" SIZE="30">
<BR>
<BR>
Password:<BR>
<INPUT TYPE="text" NAME="Password" SIZE="30">
<BR>
<BR>
Confirm Password:<BR>
<INPUT TYPE="text" NAME="Confirm" SIZE="30">
<BR>
<BR>
<CENTER>
<INPUT TYPE="Submit" NAME="Apply" VALUE="Submit" OnSubmit="vbscript: Validate">
</CENTER>
</TD>
</TR>
</TABLE>
</FORM></CENTER>
</BODY>
</HTML>
Re: Validate text boxes with vbscript
Ok, I've gotten it to call the function by moving the 'OnSubmit' like this:
Code:
<FORM NAME="Logn" METHOD="post" OnSubmit="vbscript: Validate" ACTION="index.shtml">
<TABLE BORDER="1" CELLSPACING="0" CELLPADDING="7" WIDTH="250" BGCOLOR="#6B656B">
<TR>
<TD>
<H3>Create a New Account</H3>
User Name:<BR>
<INPUT TYPE="text" '...........
<BR>
<CENTER>
<INPUT TYPE="Submit" NAME="Apply" VALUE="Submit">
</CENTER>
BUT,,,, it still calls the index.asp page even when the function returns false.
How do I fix that?
Re: Validate text boxes with vbscript
I gave up on this and switched to a javascript that MS has up:
http://support.microsoft.com/kb/216435
I'm not marking the thread resolved because I still don't have a vbscript solution.
Re: Validate text boxes with vbscript
And you probably don't want a VB script solution.
VBScript is not supported in all browsers.
stay with javascript solution