Jump to content

complete form validation before executing javascript?


squigs

Recommended Posts

Hello

 

I am building a form which contains javascript validation. What I am trying to accomplish is a client-side form validation and if there are no alerts within that process another process begins. The problem is that both are being triggered by the same onclick event and I don't know how to rectify it.

 

//validation below
var frmvalidator  = new Validator("email_form_with_attachments");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("project_name","req","Please tag your project with a name");
frmvalidator.addValidation("project_location","req","Where is your project located?");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
frmvalidator.addValidation("uploaded_file","req","Select your files to submit");
frmvalidator.addValidation("message","req","Please enter a message");

//second function (an animated .gif)
function loadSubmit() {
var ProgressImage = document.getElementById('progress_image');
document.getElementById("progress").style.visibility = "visible";
setTimeout(function(){ProgressImage.src = ProgressImage.src},100);
return true;
}

 

Thank you

I have come up with a solution to my problem through a little trial and error. It seems only partly logical to me but it did the trick. I had been playing around with ifs and elses but the key turned out to be setting the focus back to a field after an alert.

//validation below
var frmvalidator  = new Validator("email_form_with_attachments");
frmvalidator.addValidation("name","req","Please provide your name"); 
frmvalidator.addValidation("project_name","req","Please tag your project with a name");
frmvalidator.addValidation("project_location","req","Where is your project located?");
frmvalidator.addValidation("email","req","Please provide your email");
frmvalidator.addValidation("email","email","Please enter a valid email address"); 
frmvalidator.addValidation("uploaded_file","req","Select your files to submit");
frmvalidator.addValidation("message","req","Please enter a message");

//new code inserted below
function loadSubmit() {
if(document.getElementById('uploaded_file').value == ""){
	 this.setFocus("name");
	 ret=false;
}else{
var ret=true;
var ProgressImage = document.getElementById('progress_image');
document.getElementById("progress").style.visibility = "visible";
setTimeout(function(){ProgressImage.src = ProgressImage.src},100);
}
return ret;
}

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.