473,396 Members | 1,992 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Simple Form Validation

I have a very simple form:

<html>
<head>
</head>
<body>
<%
function ValForm()
if len(document.form.newapp.all("AccessCode").Value) = 4 then
document.form.newapp.submit()
else
msgbox "Access Code in Improper Format"
end if
end function
%>
<form action="process.asp" method="Post">
<form name="newapp">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValForm()">
</form>
</body>
</html>

As you can see, I am attempting to do some very simple form validation. I
am getting
a script error. Any help or any other suggestions on how to do what I am
attempting?

Thanks,

rh
Jul 19 '05 #1
7 2948
After an exhaustive research, here is what I came up with:

<html>
<head>
<script language="vbscript">
Sub newapp_onsubmit()
'msgbox len(document.newapp.all("AccessCode").Value)
' window.event.returnValue = false
if len(document.newapp.all("AccessCode").Value) < 4 then
msgbox "Improper Format"
window.event.returnValue = false
elseif msgbox("Cancel submit",vbYesNo) = vbYes then
window.event.returnValue = false
else
window.event.returnValue = true
end if
end Sub
</script>
</head>
<body>
<form name="newapp" action="process.asp" method="Post">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="submit" value="Submit" Name="Submit">
</form>
</body>
</html>

Works! Looking for other suggestions as well.

Thanks,

rh
Jul 19 '05 #2
On Tue, 18 May 2004 10:00:44 -0400, "r0adhog"
<ro*****@nospam.phreaker.net> wrote:
I have a very simple form:

<html>
<head>
</head>
<body>
<%
function ValForm()
if len(document.form.newapp.all("AccessCode").Value) = 4 then
document.form.newapp.submit()
else
msgbox "Access Code in Improper Format"
end if
end function
%>
<form action="process.asp" method="Post">
<form name="newapp">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValForm()">
</form>
</body>
</html>

As you can see, I am attempting to do some very simple form validation. I
am getting
a script error. Any help or any other suggestions on how to do what I am
attempting?


Obligatory question: *What* script error?

Beyond that, the msgbox wouldn't pop up on the client side even if it
worked as you intended.

See:

http://www.aspfaq.com/show.asp?id=2198

(Which is likely the error you neglected to post...)

Jeff
Jul 19 '05 #3
Thanks for the input!

rh
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:40****************@msnews.microsoft.com...
On Tue, 18 May 2004 10:00:44 -0400, "r0adhog"
<ro*****@nospam.phreaker.net> wrote:
I have a very simple form:

<html>
<head>
</head>
<body>
<%
function ValForm()
if len(document.form.newapp.all("AccessCode").Value) = 4 then
document.form.newapp.submit()
else
msgbox "Access Code in Improper Format"
end if
end function
%>
<form action="process.asp" method="Post">
<form name="newapp">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValForm()">
</form>
</body>
</html>

As you can see, I am attempting to do some very simple form validation. Iam getting
a script error. Any help or any other suggestions on how to do what I am
attempting?


Obligatory question: *What* script error?

Beyond that, the msgbox wouldn't pop up on the client side even if it
worked as you intended.

See:

http://www.aspfaq.com/show.asp?id=2198

(Which is likely the error you neglected to post...)

Jeff

Jul 19 '05 #4
Something else to keep in mind: calling a function from the onclick event of
a submit element can cause unpredictable results - maybe the function gets
called, maybe it doesn't. I've had IE ignore function calls. Better to
change the SUBMIT to a BUTTON, and submit the form at the end of your
function, like you're doing.

"r0adhog" <ro*****@nospam.phreaker.net> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
Thanks for the input!

rh
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:40****************@msnews.microsoft.com...
On Tue, 18 May 2004 10:00:44 -0400, "r0adhog"
<ro*****@nospam.phreaker.net> wrote:
I have a very simple form:

<html>
<head>
</head>
<body>
<%
function ValForm()
if len(document.form.newapp.all("AccessCode").Value) = 4 then
document.form.newapp.submit()
else
msgbox "Access Code in Improper Format"
end if
end function
%>
<form action="process.asp" method="Post">
<form name="newapp">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValForm()">
</form>
</body>
</html>

As you can see, I am attempting to do some very simple form validation. Iam getting
a script error. Any help or any other suggestions on how to do what I amattempting?


Obligatory question: *What* script error?

Beyond that, the msgbox wouldn't pop up on the client side even if it
worked as you intended.

See:

http://www.aspfaq.com/show.asp?id=2198

(Which is likely the error you neglected to post...)

Jeff


Jul 19 '05 #5
You are correct sir, I changed as you suggested and works great!

Thanks again!

rh

"William Morris" <ne***************************@seamlyne.com> wrote in
message news:2g************@uni-berlin.de...
Something else to keep in mind: calling a function from the onclick event of a submit element can cause unpredictable results - maybe the function gets
called, maybe it doesn't. I've had IE ignore function calls. Better to
change the SUBMIT to a BUTTON, and submit the form at the end of your
function, like you're doing.

"r0adhog" <ro*****@nospam.phreaker.net> wrote in message
news:OB**************@TK2MSFTNGP12.phx.gbl...
Thanks for the input!

rh
"Jeff Cochran" <jc*************@naplesgov.com> wrote in message
news:40****************@msnews.microsoft.com...
On Tue, 18 May 2004 10:00:44 -0400, "r0adhog"
<ro*****@nospam.phreaker.net> wrote:

>I have a very simple form:
>
><html>
><head>
></head>
><body>
><%
>function ValForm()
> if len(document.form.newapp.all("AccessCode").Value) = 4 then
> document.form.newapp.submit()
> else
> msgbox "Access Code in Improper Format"
> end if
>end function
>%>
><form action="process.asp" method="Post">
><form name="newapp">
><input type="password" autocomplete="off" name="AccessCode"></td>
><input type="button" value="Submit" Name="Submit" onclick="ValForm()"> ></form>
></body>
></html>
>
>As you can see, I am attempting to do some very simple form
validation.
I
>am getting
>a script error. Any help or any other suggestions on how to do what
I am >attempting?

Obligatory question: *What* script error?

Beyond that, the msgbox wouldn't pop up on the client side even if it
worked as you intended.

See:

http://www.aspfaq.com/show.asp?id=2198

(Which is likely the error you neglected to post...)

Jeff



Jul 19 '05 #6
Second Solution

<html>
<head>
<script language="vbscript">
Sub validform()
if len(document.newapp.all("AccessCode").Value) < 4 then
msgbox "Improper Format"
window.event.returnValue = false
elseif msgbox("Cancel submit",vbYesNo) = vbYes then
document.newapp.submit
else
window.event.returnValue = false
end if
end Sub
</script>
</head>
<body>
<form name="newapp" action="process.asp" method="Post">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValidForm()">
</form>
</body>
</html>

Thanks for the input folks!

rh
Jul 19 '05 #7
Just wanted to post the obvious, since no one mentioned it.

The code between <% and %> runs on the server. Your onClick events run on
the client (usually a browser)

So if you were to view the source of your code in the browser, you'd see no
"function ValForm()" hence the error on the browser.

Your solution uses VBScript on the CLIENT, so bear in mind that it probably
won't work in browsers other than IE.

"r0adhog" <ro*****@nospam.phreaker.net> wrote in message
news:uP**************@TK2MSFTNGP11.phx.gbl...
I have a very simple form:

<html>
<head>
</head>
<body>
<%
function ValForm()
if len(document.form.newapp.all("AccessCode").Value) = 4 then
document.form.newapp.submit()
else
msgbox "Access Code in Improper Format"
end if
end function
%>
<form action="process.asp" method="Post">
<form name="newapp">
<input type="password" autocomplete="off" name="AccessCode"></td>
<input type="button" value="Submit" Name="Submit" onclick="ValForm()">
</form>
</body>
</html>

As you can see, I am attempting to do some very simple form validation. I
am getting
a script error. Any help or any other suggestions on how to do what I am
attempting?

Thanks,

rh

Jul 19 '05 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

17
by: Phil Powell | last post by:
Where can I find an online PHP form validator script library to use? I have tried hacking the one here at work for weeks now and it's getting more and more impossible to customize, especially now...
4
by: TG | last post by:
I have a validation form that must behave differently based on the results of a PHP validation check. I have a post command at the top of my form that calls itself. I don't leave the form when...
3
by: Marc Llenas | last post by:
Hi there, I'm stuck on a validation function for a form and I cannot figure out what the problem is. The page is in ASP. Any ideas? The function being called is: <script...
16
by: Hosh | last post by:
I have a form on a webpage and want to use JavaScript validation for the form fields. I have searched the web for form validation scripts and have come up with scripts that only validate...
2
by: Hazzard | last post by:
I just realized that the code I inherited is using all asp.net server controls (ie. webform controls) and when I try to update textboxes on the client side, I lose the new value of the textbox when...
18
by: Q. John Chen | last post by:
I have Vidation Controls First One: Simple exluce certain special characters: say no a or b or c in the string: * Second One: I required date be entered in "MM/DD/YYYY" format: //+4 How...
9
by: julie.siebel | last post by:
Hello all! As embarrassing as it is to admit this, I've been designing db driven websites using javascript and vbscript for about 6-7 years now, and I am *horrible* at form validation. To be...
27
by: Chris | last post by:
Hi, I have a form for uploading documents and inserting the data into a mysql db. I would like to validate the form. I have tried a couple of Javascript form validation functions, but it...
11
by: Rik | last post by:
Hello guys, now that I'm that I'm working on my first major 'open' forms (with uncontrolled users I mean, not a secure backend-interface), I'd like to add a lot of possibilities to check wether...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.