|
 |
aspx thread: Using javascript for form validation
Message #1 by "Carole D. Sullivan" <carolesullivan@e...> on Wed, 30 Oct 2002 21:55:25
|
|
I am attempting to use javascript to STOP my form from submission when
BOTH input text boxes are empty. I get the error message indicated in
the javascript, but IT DOES NOT STOP MY FORM from being submitted.
I do not have a standard submit button on this form, I have about 10
different buttons to choose from, the run subroutine and then send you to
another page.
Code:
Javascript:
<script language="javascript">
<!--
function validate() {
var blnValid = true;
mEmpId=document.Form1.txtEmployeeId.value;
mChkNo=document.Form1.txtCheckAdviceNumber.value;
if (mEmpId == '' && mChkNo == '')
{blnValid = false;
alert("Boolean Value = " + blnValid);
}
else
{blnValid = true;}
return blnValid
}
//-->
</script>
+++++++++++++++++++++++++++++++++++++++++++
and the only code currently in my HTML to call this is:
<form id="Form1" method="post" runat="server" onsubmit="validate();">
Any suggestions would be greatly appreciated. I was unable to get the
custom validator to kick in, I would happy to take suggestions on that
one as well.
Thanks in advance,
Carole
Message #2 by "Chris Kersey" <ckersey@m...> on Wed, 30 Oct 2002 13:55:15 -0800
|
|
try returning your validate() routine like below:
<form id="Form1" method="post" runat="server" onsubmit="return validate();">
instead of just
<form id="Form1" method="post" runat="server" onsubmit="validate();">
chris
----- Original Message -----
From: "Carole D. Sullivan" <carolesullivan@e...>
To: "ASP.NET" <aspx@p...>
Sent: Wednesday, October 30, 2002 9:55 PM
Subject: [aspx] Using javascript for form validation
> I am attempting to use javascript to STOP my form from submission when
> BOTH input text boxes are empty. I get the error message indicated in
> the javascript, but IT DOES NOT STOP MY FORM from being submitted.
>
> I do not have a standard submit button on this form, I have about 10
> different buttons to choose from, the run subroutine and then send you to
> another page.
>
> Code:
>
> Javascript:
> <script language="javascript">
> <!--
> function validate() {
> var blnValid = true;
> mEmpId=document.Form1.txtEmployeeId.value;
> mChkNo=document.Form1.txtCheckAdviceNumber.value;
> if (mEmpId == '' && mChkNo == '')
> {blnValid = false;
> alert("Boolean Value = " + blnValid);
>
> }
> else
> {blnValid = true;}
> return blnValid
> }
> //-->
> </script>
>
> +++++++++++++++++++++++++++++++++++++++++++
>
> and the only code currently in my HTML to call this is:
>
> <form id="Form1" method="post" runat="server" onsubmit="validate();">
>
> Any suggestions would be greatly appreciated. I was unable to get the
> custom validator to kick in, I would happy to take suggestions on that
> one as well.
>
> Thanks in advance,
>
> Carole
> ---
>
> ASP.NET 1.0 Namespace Reference with C#
> http://www.wrox.com/acon11.asp?ISBN=1861007442
>
> ASP.NET 1.0 Namespace Reference with VB.NET
> http://www.wrox.com/acon11.asp?ISBN=1861007450
>
> These books are a complete reference to the ASP.NET namespaces
> for developers who are already familiar with using ASP.NET.
> There is no trivial introductory material or useless .NET
> hype and the presentation of the namespaces, in an easy-to use
> alphabetical order ensures a user-friendly reference format.
> We provide in-depth coverage of all the major ASP.NET classes,
> giving you those real-world tips that the documentation doesn't
> offer, and demonstrating complex techniques with simple
> examples.
>
> ---
Message #3 by "Carole D. Sullivan" <carolesullivan@e...> on Thu, 31 Oct 2002 17:15:19
|
|
THANKS Chris, your solution worked!
> I am attempting to use javascript to STOP my form from submission when
B> OTH input text boxes are empty. I get the error message indicated in
t> he javascript, but IT DOES NOT STOP MY FORM from being submitted.
> I do not have a standard submit button on this form, I have about 10
d> ifferent buttons to choose from, the run subroutine and then send you
to
a> nother page.
> Code:
> Javascript:
<> script language="javascript">
<> !--
f> unction validate() {
v> ar blnValid = true;
m> EmpId=document.Form1.txtEmployeeId.value;
m> ChkNo=document.Form1.txtCheckAdviceNumber.value;
i> f (mEmpId == '' && mChkNo == '')
> {blnValid = false;
> alert("Boolean Value = " + blnValid);
>
> }
> else
> {blnValid = true;}
> return blnValid
> }
/> /-->
> </script>
> +++++++++++++++++++++++++++++++++++++++++++
> and the only code currently in my HTML to call this is:
> <form id="Form1" method="post" runat="server" onsubmit="validate();">
> Any suggestions would be greatly appreciated. I was unable to get the
c> ustom validator to kick in, I would happy to take suggestions on that
o> ne as well.
> Thanks in advance,
> Carole
|
|
 |