469,936 Members | 2,444 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,936 developers. It's quick & easy.

error checking on form

hey peoples.

I have a simple form (currently two fields) which is then passed to an ASP
page thats stores the data in a dbase

I have an error checking script which I can't get to work. the script is :
<script language="JavaScript">

<!-- Hide from older browsers...

//Function to check form is filled in correctly before submitting
function CheckForm () {

//Intialise variables
var errorMsg = "";
var errorMsgLong = "";

//Check for a name
if (document.frmregnewuser.name.value == ""){
errorMsg += "\n\tName \t\t- Enter your Name";
}

//Check for comments
if (document.frmregnewuser.e-mail.value == ""){
errorMsg += "\n\tComments \t- Enter a valid email address";
}
//If there is aproblem with the form then display an error

if ((errorMsg != "") || (errorMsgLong != "")){
msg =
"_________________________________________________ __________________\n\n";
msg += "Your registration could not be completed because there are
problem(s) with the form.\n";
msg += "Please correct the problem(s) and re-submit the form.\n";
msg +=
"_________________________________________________ __________________\n\n";
msg += "The following field(s) need to be corrected: -\n";

errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
return false;
}

return true;
}

// -->
</script>
I have the submit button and the following code in the form

onsubmit = "return checkform ();"

but it doesn't run the check...can anyone see anything obvious??

many thanks

Jul 20 '05 #1
2 1457
Alistair wrote:
errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);


This should be just:
alert(msg + errorMsg + "\n" + errorMsgLong);
JW

Jul 20 '05 #2
"Alistair" <news@*remove*alistairb.co.uk> writes:
I have an error checking script which I can't get to work. the script is :
A description of how it fails, best in compairison to what it should do,
would make it a *lot* easier to check.
<script language="JavaScript">
In HTML 4, the type attribute is *required*. Use
<script type="text/javascript">
It works in all browsers and is also correct.
<!-- Hide from older browsers...
Not necessary.
if (document.frmregnewuser.e-mail.value == ""){
"e-mail" is not a valid identifier. This gives the error that "mail"
is an undefined variable. Write it as:
if (document.forms['frmrengewuser'].elements['e-mail'].value == ""){

errorMsg += alert(msg + errorMsg + "\n" + errorMsgLong);
As Janwillem Borleffs said, the "errorMsg +=" shouldn't be there.
but it doesn't run the check...can anyone see anything obvious??


You should enable the showing of script errors when you program.
I assueme you use IE, since you don't say anything.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Marc S. Gibian | last post: by
1 post views Thread by Wayne Aprato | last post: by
2 posts views Thread by akhilesh.noida | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.