Custom Validation - Part 2

ChiefGoFor 22 Aug, 2015
This is a similar issue as before, but the question is more precise...

I have 4 check boxes that are not grouped.
This is because some of them have text boxes between them.
Only certain combinations are valid. (1, 2, 3, 4, or 1&2)

When I don't meet the requirements, it shows the error. If I fix it and check the right boxes, it still shows the error even though the problem was fixed.
This is on Submit, not Save. Save does not do any validation.

I've added sample code below. Some variables have been renamed for clarity.

Any help is appreciated. Thank you!

function check_checkboxes(what_button){
	var has_error = 1; //We will set to 0 when checkboxes are validated
	
	var chkbox_a = jQuery('#chkbox_a').attr("checked");
	var chkbox_b = jQuery('#chkbox_b').attr("checked");
	var chkbox_c = jQuery('#chkbox_c').attr("checked");
	var chkbox_d = jQuery('#chkbox_d').attr("checked");
	
	if(    (chkbox_a == 'checked' && chkbox_b != 'checked' && chkbox_c != 'checked' && chkbox_d != 'checked')
		|| (chkbox_a != 'checked' && chkbox_b == 'checked' && chkbox_c != 'checked' && chkbox_d != 'checked')
		|| (chkbox_a != 'checked' && chkbox_b != 'checked' && chkbox_c == 'checked' && chkbox_d != 'checked')
		|| (chkbox_a != 'checked' && chkbox_b != 'checked' && chkbox_c != 'checked' && chkbox_d == 'checked')
		|| (chkbox_a == 'checked' && chkbox_b == 'checked' && chkbox_c != 'checked' && chkbox_d != 'checked'))
	{
		has_error = 0;
	}
	
	var req = "validate['tooltip']";
	
	if(what_button == 'submit' && has_error == 1){
		jQuery('#chkbox_a').addClass(req);
	} else {
		jQuery('#chkbox_a').removeClass(req); //Calling this does not stop this record from
	}
}
This topic is locked and no more replies can be posted.