Reputation: 414
I have this website currently and giving me problems because I am running two forms on the website, and jquery is getting confused about the validation because its just finding the INPUT, and since there is two forms it's getting an error because the input is blank in the other form...
How do I select a specific input in jquery instead of the universal input?
// Email Form
required = ["fullName" , "emailAddress"];
email = $("#emailAddress");
errornotice = $("#error");
emptyerror = "Required field.";
emailerror = "Enter a valid e-mail.";
$("#theformemail").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
if ((input.val() == "") || (input.val() == emptyerror)) {
input.addClass("needsfilled");
input.val(emptyerror);
} else {
input.removeClass("needsfilled");
}
}
// Validate the e-mail.
if (!/^([a-zA-Z0-9_\.\-])+\@(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/.test(email.val())) {
email.addClass("needsfilled");
email.val(emailerror);
}
//if any inputs on the page have the class 'needsfilled' the form will not submit
if ($(":input").hasClass("needsfilled")) {
return false;
} else {
$("#newOne").show().delay(2000);
errornotice.hide();
return true;
}
});
??????? Here is also the actual testing page of the website.
http://www.trento110.com/site/index.php
If you click on - private events there is one form.. then if you click on "send to phone on the botton.. there is the other form, and notice the conflict.
Thanks in advance.
Upvotes: 1
Views: 644
Reputation: 1063
please try this
$("#theformemail").submit(function(){
//Validate required fields
for (i=0;i<required.length;i++) {
var input = $('#'+required[i]);
//change this line with
var input =$(this).find('#'+required[i]);
Upvotes: 2