Hey guys, Need help with what i thought was a fairly easy addition to my validation script. However it’s not working :-/
I have a validation script that works great. However, i am having trouble setting the variable? I may not be targeting/searching it correctly? I want to get the variable correct, and properly perform an IF statement - for a validation script.
You can see where i commented out various ways of trying to get the var source2, and source3. Then a little further, you can see the IF statement im having trouble with (IF CQ.). Its loggically VERY simple.
IF formType = ‘cq_form’ -> Make source2, and source3 REQUIRED fields.
function SchoolFormValidation() {
formType = $("#thechoices").val();
var counter = 0;
var returnvalue = true;
if (formType != 'cb_ht' && formType != 'axd_ht') {
schoolSelect = $('#' + formType).find("select[name^='src']");
schoolSelect.each(function() {
// We have a school
if ($(this).val()) {
var thisForm = $(this).closest('table');
var frm = $(this).closest('form');
var school = thisForm.find("select[name^='cid']");
var sub = thisForm.find("select[name^='name']");
//var source2 = frm.find("input[id^='source2']");
//var source3 = frm.find("input[id^='source3']");
//var source2 = document.getElementById("source2").value;
//var source3 = document.getElementById("source3").value;
var source2 = $('#source2').closest('form', 'source2').attr('id');
var source3 = $('#source3').closest('form', 'source3').attr('id');
if (!sub.val()) {
sub = thisForm.find("input[name^='name']");
}
var degree = thisForm.find("input[name^='degree']");
var prog = thisForm.find("input[name^='program']");
// Count the Schools
counter += 1;
// Validate the fields
if (!school.val()) {
sfm_show_error_msg('Please select the school.');
var targetOffset = school.offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
else if (!sub.val()) {
sfm_show_error_msg('Please select/fill in the Sub.');
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
else if (!degree.val()) {
sfm_show_error_msg('Please enter the degree.');
var targetOffset = degree.offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
else if (!prog.val()) {
sfm_show_error_msg('Please enter the program.');
var targetOffset = prog.offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
//WHERE IM HAVING TROUBLE----->IF formType = CQ, REQUIRE source2, and source3 fields. I don't think im setting the source2, source3 vars properly above?
if(formType == 'cq_form'){
var source2 = $('#source2').closest('form', 'source2').attr('id');
var source3 = $('#source3').closest('form', 'source3').attr('id');
if (!source2.val()) {
sfm_show_error_msg('Please Enter POI');
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
else if (!source3.val()) {
sfm_show_error_msg('Please Enter Field1');
var targetOffset = $(this).offset().top;
$('html,body').animate({scrollTop: targetOffset}, 1000);
returnvalue = false;
return false;
}
}//end CQ2 IF
}
});
just need to properly get the source2, source3 vars and make that IF statement work.
Thanks in advance,
jt
note: This is similar to a previous post i made - however, its a little different than what i was asking previously. Didn’t want to revive a dead (& almost unrelated) thread.