J
JNariss
Hello,
I am fairly new to asp and jscript and am now in the process of
learning some form validation. I am taking one step at a time by
validating each field and testing it before moving onto the next one to
be sure I am correct. I ran into a problem with my validation when I
added an else if code to my code.
Here is what I tried to do: Form (ITTermination) has a field
(EmployeeName) which I would like to validate to check for no value and
alpha characters A - Z only, no numbers.
This code worked great to ONLY to validate a no value in the field:
<script language="JavaScript">
<!--
function validate_form ( )
{
valid = true;
if ( document.ITTermination.EmployeeName.value == "" )
{
alert("Please enter first and last name for 'Employee Name'
using only characters." );
document.ITTermination.EmployeeName.focus();
return (false);
}
return valid;
}
//-->
</script>
Here is the text label info with the validation check included in the
onBlur event:
<label>Employee Name:
<input name="EmployeeName" type="text" id="EmployeeName"
style="background-color: #C0C0C0" size="35" maxlength="35"
onBlur="validate_form();"/>
</label>
So when I got daring I decided to check that no numbers are entered
into the field and came up with this code which is not working:
<script language="javascript">
<!--
function validate_form () {
valid = true;
if (document.ITTermination.EmployeeName.value == "" )
{
alert("Please enter first and last name for 'Employee Name' using
only characters." );
document.ITTermination.EmployeeName.focus();
return (false);
}
else if (document.ITTermination.EmployeeName.value ==
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
{
alert("Please do not use numbers within the Employee Name field. Only
alphabetic characters are allowed.")
document.ITTermination.EmployeeName.focus();
return (false);
}
return valid;
}
//-->
</script>
I even tried using else if (document.ITTermination.EmployeeName.value
== "alpha") and that did not work either.
If someone would be so kind to help me out I will be on my way to the
next field. I would like to keep adding validations to this form within
the one script validate_form( ).
Thanks in advance,
Justine
I am fairly new to asp and jscript and am now in the process of
learning some form validation. I am taking one step at a time by
validating each field and testing it before moving onto the next one to
be sure I am correct. I ran into a problem with my validation when I
added an else if code to my code.
Here is what I tried to do: Form (ITTermination) has a field
(EmployeeName) which I would like to validate to check for no value and
alpha characters A - Z only, no numbers.
This code worked great to ONLY to validate a no value in the field:
<script language="JavaScript">
<!--
function validate_form ( )
{
valid = true;
if ( document.ITTermination.EmployeeName.value == "" )
{
alert("Please enter first and last name for 'Employee Name'
using only characters." );
document.ITTermination.EmployeeName.focus();
return (false);
}
return valid;
}
//-->
</script>
Here is the text label info with the validation check included in the
onBlur event:
<label>Employee Name:
<input name="EmployeeName" type="text" id="EmployeeName"
style="background-color: #C0C0C0" size="35" maxlength="35"
onBlur="validate_form();"/>
</label>
So when I got daring I decided to check that no numbers are entered
into the field and came up with this code which is not working:
<script language="javascript">
<!--
function validate_form () {
valid = true;
if (document.ITTermination.EmployeeName.value == "" )
{
alert("Please enter first and last name for 'Employee Name' using
only characters." );
document.ITTermination.EmployeeName.focus();
return (false);
}
else if (document.ITTermination.EmployeeName.value ==
"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz")
{
alert("Please do not use numbers within the Employee Name field. Only
alphabetic characters are allowed.")
document.ITTermination.EmployeeName.focus();
return (false);
}
return valid;
}
//-->
</script>
I even tried using else if (document.ITTermination.EmployeeName.value
== "alpha") and that did not work either.
If someone would be so kind to help me out I will be on my way to the
next field. I would like to keep adding validations to this form within
the one script validate_form( ).
Thanks in advance,
Justine