Click to See Complete Forum and Search --> : validation


nfuego2
06-13-2003, 01:34 PM
I am trying to set validation to a form for required fields and can not seem to get the coding to work the link to the web page where I am using it is www.futurechef.com/studentinfo.asp When you click the submit button the alerts do not activate. Can you take a look and advise??? Thanks

P.S. Here is part of the code I am using - am I missing something?

//Preload images
var empty = new Image(); empty.src = "fieldempty.gif";
var email = new Image(); email.src = "emailerror.gif";
var zipcd = new Image(); zipcd.src = "ziperror.gif";
var phone = new Image(); phone.src = "phoneerror.gif";

var haveerrors = 0;
function showImage(imagename, imageurl, errors) {
document[imagename].src = imageurl;
if (!haveerrors && errors) haveerrors = errors;
}

function validateForm(f) {
haveerrors = 0;
(f.fname.value.length < 1) // validate first name length
? showImage("firstnameerror", "fieldempty.gif", true) // no semi-colon after this line!
: showImage("firstnameerror", "blankimage.gif", false); // true = errors, false = no errors

(f.lname.value.length < 1) // validate last name length
? showImage("lastnameerror", "fieldempty.gif", true)
: showImage("lastnameerror", "blankimage.gif", false);

(f.zip.value.length != 5) // validate zip code length
? showImage("ziperror", "ziperror.gif", true)
: showImage("ziperror", "blankimage.gif", false);

phonenumlength = f.area.value.length +
f.exchange.value.length + f.number.value.length;

(phonenumlength != 10) // validate phone number length
? showImage("phoneerror", "phoneerror.gif", true)
: showImage("phoneerror", "blankimage.gif", false);

(f.email.value.search("@") == -1 || f.email.value.search("[.*]") == -1) // validate email
? showImage("emailerror", "emailerror.gif", true)
: showImage("emailerror", "blankimage.gif", false);

return (!haveerrors);
}
// End -->
</script>
</HEAD>

<body>
<form name="myform" action="mailto:fbringas@futurechef.com" method="post" enctype="text/plain" onSubmit="return validateForm();">

Khalid Ali
06-13-2003, 03:12 PM
The only think I can see you are missing is the reference to the form

change this code

onSubmit="return validateForm();"

to

onSubmit="return validateForm(this);"

Khalid Ali
06-13-2003, 03:27 PM
That is whole new problem...you need to check theurls for the images..
here is the one thats in the code

http://www.futurechef.com/fieldempty.gif

but it broken..just type the link in your address bar of the browser and hit enter..if the image shows in the browser then its good else its not the correct path

Khalid Ali
06-13-2003, 05:07 PM
Thanks for the PM..and you are welcome....