squigs Posted August 27, 2012 Share Posted August 27, 2012 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 Quote Link to comment https://forums.phpfreaks.com/topic/267675-complete-form-validation-before-executing-javascript/ Share on other sites More sharing options...
squigs Posted August 27, 2012 Author Share Posted August 27, 2012 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; } Quote Link to comment https://forums.phpfreaks.com/topic/267675-complete-form-validation-before-executing-javascript/#findComment-1373067 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.