Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > ASP General > Second form validation problem

Reply
Thread Tools

Second form validation problem

 
 
John
Guest
Posts: n/a
 
      07-09-2006
Hi

I have two forms on my page. Both use javascript to validate input before
submission. Problem is that first form does the validation fine but the
second form gets submitted without any validation taking place. Simplified
form of code is given below.

What am I doing wrong?

Thanks

Regards


<html>
<head>

<script type="text/javascript">
// <![CDATA[
function validate()
{
// validation code here, which works fine
}

function valid1()
{
f=document.getElementById("Form1");
if(f.StaffCode.value<>"HS01")
{
alert("Invalied code. Please re-enter.");
f.StaffCode.focus();
return false;
}
}

// ]]>
</script>

</head>
<body>
<!--This form validates fine using function validate-->
<form id="theform" method="post" action="abc.asp" onsubmit="return
validate();">
<input type="hidden" name="mode" value="1">
<input type="text" name="muser" id="muser" value="" size="20">
<input type="password" name="mpass" id="mpass" value="" size="20">
<input name="bu_submit" type="image"
src="images/box/bu_login_sm.gif" border="0"
class="noborder" style="height: 31px;">
</form>

<!--This form does not validate using function valid1-->
<form id="Form1" method="post" action="xyz.asp" onsubmit="return
valid1();">
<input type="text" name="StaffCode" id="StaffCode" value=""
size="30">
<input name="bu_submit" type="image" src="images/box/bu_login.gif"
border="0" class="noborder"
style="height: 31px;">
</form>
</body>
</html>



 
Reply With Quote
 
 
 
 
Mike Brind
Guest
Posts: n/a
 
      07-09-2006

John wrote:
> Hi
>
> I have two forms on my page. Both use javascript to validate input before
> submission. Problem is that first form does the validation fine but the
> second form gets submitted without any validation taking place. Simplified
> form of code is given below.
>
> What am I doing wrong?
>


If you want to know what's wrong with your javascript, you should post
to a javascript group - microsoft.public.scripting.jscript, for
example.

But client side validation is not recommended. It does not work for
those with javascript disabled, or those that want to get round it.
And having acceptable log in values accessible to all through View
Source rather defeats the whole point. You should move to server-side
validation.

--
Mike Brind

 
Reply With Quote
 
 
 
 
John
Guest
Posts: n/a
 
      07-09-2006
Thanks. I just want a way to validate the second form and not necessarily
via javascript. Any help would be appreciated. The validation required is
not fort Knox standard though, just to deter a casual user.

Thanks

Regards

"Mike Brind" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed) ups.com...
>
> John wrote:
>> Hi
>>
>> I have two forms on my page. Both use javascript to validate input before
>> submission. Problem is that first form does the validation fine but the
>> second form gets submitted without any validation taking place.
>> Simplified
>> form of code is given below.
>>
>> What am I doing wrong?
>>

>
> If you want to know what's wrong with your javascript, you should post
> to a javascript group - microsoft.public.scripting.jscript, for
> example.
>
> But client side validation is not recommended. It does not work for
> those with javascript disabled, or those that want to get round it.
> And having acceptable log in values accessible to all through View
> Source rather defeats the whole point. You should move to server-side
> validation.
>
> --
> Mike Brind
>



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
first form is ignored, second form is forms[0] why? groups2@reenie.org Javascript 5 08-05-2007 01:13 AM
Second form validation problem John ASP .Net 1 07-09-2006 06:32 AM
how to pass value from first form to second form? =?Utf-8?B?YzY3NjIyOA==?= ASP .Net 2 01-11-2006 11:15 PM
Form Validation Problem...Persisiting form fields on validation failure. bnp Javascript 4 05-12-2004 12:16 PM
Web form validation vs object validation Colin Basterfield ASP .Net 1 11-29-2003 12:10 AM



Advertisments