[thelist] Javascript conditional help

Sean Stephens lasso at treefroginteractive.com
Tue Oct 2 12:23:15 CDT 2001


Greetings

I'm trying to add two javascript validations using the "OnSubmit" handler
together so that OnSubmit first a) validates the fields being empty and if
the fields are not empty b) disables the submit button for future use.

I can't seem to get them to work together, and have spent a week filtering
through javscript manuals trying to learn enough about conditionals to
figure it out.

I'm trying to glue validateForm and disableForm together.

CHECK FOR EMPTY 

var email = new Image(); email.src = "Errorpics/email.gif";
var email = new Image(); email.src = "Errorpics/select.gif";

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

function validateForm(f) {
haveerrors = 0;

(f.select1.value.length < 1)
? showImage("select1error", "Errorpics/select.gif", true)
: showImage("select1error", "Errorpics/pixel.gif", false);

(f.textfield3.value.search("@") == -1 || f.textfield3.value.search("[.*]")
== -1) 
? showImage("textfield3error", "Errorpics/email.gif", true)
: showImage("textfield3error", "Errorpics/pixel.gif", false);

return (!haveerrors);
}

IF EMPTY DISABLE FORM SUBMIT

function disableForm(theform) {
if (document.all || document.getElementById) {
for (i = 0; i < theform.length; i++) {
var tempobj = theform.elements[i];
if (tempobj.type.toLowerCase() == "submit" || tempobj.type.toLowerCase() ==
"reset")
tempobj.disabled = true;
}
setTimeout('alert("This page has already been submitted. Please do not
submit twice.")', 2000);
return true;
}
else {
alert("The form has been submitted.  As you are not using IE 4+ or NS 6, the
submit button was not disabled on form submission.");
return false;
   }
}





More information about the thelist mailing list