Jump to content

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;
}

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.