Osaurus
06-11-2002, 12:31 PM
Hi all,
I`m pulling my hair out over some JavaScript form validation that probably has a simple solution (if only I knew it ha!). I have 5 text boxes that are being validated in the first instance and the validation code can be seen below.
It all works fine up to the point where the E-mail text box is validated. The script recognises a lack of any data and invalid e-mails but after that I cannot seem to get the focus to pass onto the next text box and the whole thing locks up - no form submission can take place. I know that the value of true is returned if its ok to submit; false if it isn't. Can anyone point me in the right direction here - it would be greatly appreciated!
Here is the relevent <FORM> tag:
<form method="post" name="security01" action="register_new.asp" onSubmit="return checkform(this)">
A working(!) example can be found here (take no notice of all the checkboxes - these need to be validated at some point and in the first line they have been):
http://www.osaurus.org/lm_admin/register.asp
This is the JavaScript code which is a SSI:
// Check normal text fields...
function checkform (form)
{
if (form.title.value == "") {
alert( "Please enter your title." );
form.title.focus();
return false ;
}
if (form.first_name.value == "") {
alert( "Please enter your first name." );
form.first_name.focus();
return false ;
}
if (form.second_name.value == "") {
alert( "Please enter your second name." );
form.second_name.focus();
return false ;
}
if (form.email.value == "") {
alert( "Please enter a valid E-mail address. This may be used by London Management only, in case of verification and contact." );
form.email.focus();
return false ;
}
if (form.email.value.length > 0) {
var Temp = document.security01.email
var AtSym = Temp.value.indexOf('@')
var FullStop = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1 // Array is from 0 to length-1
if ((AtSym < 1) || // Must be something before '@'
(FullStop <= AtSym+1) || // Must be at least 1 valid char between '@' and '.'
(FullStop == Length ) || // Must be at least 1 valid char after '.'
(Space != -1)) // No empty spaces
alert('There is a problem with the validity of your E-mail address!');
form.email.focus();
return false ;
}
if (form.lo_ch_first.value == "") {
alert( "Please enter a Lodge/Chapter No. in the first field marked with an asterisk." );
form.lo_ch_first.focus();
return false ;
}
return true ;
}
I`m pulling my hair out over some JavaScript form validation that probably has a simple solution (if only I knew it ha!). I have 5 text boxes that are being validated in the first instance and the validation code can be seen below.
It all works fine up to the point where the E-mail text box is validated. The script recognises a lack of any data and invalid e-mails but after that I cannot seem to get the focus to pass onto the next text box and the whole thing locks up - no form submission can take place. I know that the value of true is returned if its ok to submit; false if it isn't. Can anyone point me in the right direction here - it would be greatly appreciated!
Here is the relevent <FORM> tag:
<form method="post" name="security01" action="register_new.asp" onSubmit="return checkform(this)">
A working(!) example can be found here (take no notice of all the checkboxes - these need to be validated at some point and in the first line they have been):
http://www.osaurus.org/lm_admin/register.asp
This is the JavaScript code which is a SSI:
// Check normal text fields...
function checkform (form)
{
if (form.title.value == "") {
alert( "Please enter your title." );
form.title.focus();
return false ;
}
if (form.first_name.value == "") {
alert( "Please enter your first name." );
form.first_name.focus();
return false ;
}
if (form.second_name.value == "") {
alert( "Please enter your second name." );
form.second_name.focus();
return false ;
}
if (form.email.value == "") {
alert( "Please enter a valid E-mail address. This may be used by London Management only, in case of verification and contact." );
form.email.focus();
return false ;
}
if (form.email.value.length > 0) {
var Temp = document.security01.email
var AtSym = Temp.value.indexOf('@')
var FullStop = Temp.value.lastIndexOf('.')
var Space = Temp.value.indexOf(' ')
var Length = Temp.value.length - 1 // Array is from 0 to length-1
if ((AtSym < 1) || // Must be something before '@'
(FullStop <= AtSym+1) || // Must be at least 1 valid char between '@' and '.'
(FullStop == Length ) || // Must be at least 1 valid char after '.'
(Space != -1)) // No empty spaces
alert('There is a problem with the validity of your E-mail address!');
form.email.focus();
return false ;
}
if (form.lo_ch_first.value == "") {
alert( "Please enter a Lodge/Chapter No. in the first field marked with an asterisk." );
form.lo_ch_first.focus();
return false ;
}
return true ;
}