Hello all,
There is a conflict with if conditionals in a function. It happens when the function executes twice, executes right after the first execution. The purpose of this code is to execute checkValiditity function to return either true or false after checking if the element has the class assigned to valid. Next it is supposed to switch the class from valid to invalid or the other way around according to what checkValiditity returns. Now, that code works as expected; however, the invalid class gets switched to valid(I am watching the switch in firebug) when it should be invalid. To further check the issue, I only check if data equals true and watch the class change to valid in firebug then only check if data equals false and watch the class change to invalid in firebug.

I am assuming the conflict is due to the if statements and the validateElement function executing right after another?

I am not sure how to fix this conflict. Why is this conflict happening and how do I fix this conflict?

Function code:
Code:
	function checkValiditity(element, valid)
	{
		var check = $(element).hasClass(valid);
		
		return check;
	}

function validateElement(formId, elementSelector, element, validateElement, errorContainer)
	{
		var indexValue = invalidElement.indexOf(element);
		
		$.ajax({
			type: 'POST',
			cache: false,
			url: "validate_breed",
			data: element+"="+$(elementSelector).val()+"&v="+validateElement,
			context: document.body,
			dataType: 'html',
			success: function(data){
		    	if (data == "true")
		    	{
		    		var isValid = checkValiditity(element, "valid");

		    		alert ("true executed");
		    		$(errorContainer).removeClass('element_invalid').addClass('element_valid');
		    		if (isValid == false) { $(elementSelector).removeClass('invalid').addClass('valid'); }

		    		

		    	} 
		    	else
		    	{
		    		var falseInArray = isElementInArray(element);

		    		alert("false executed");
		    		
		    		$(errorContainer).removeClass('element_valid').addClass('element_invalid');
		    		if (isValid == false) { $(elementSelector).removeClass('valid').addClass('invalid'); disableSubmit('#submit')}
		    	}
		  	}
		});
	}
Execution code:
Code:
function editRow(valId)
{
	jQuery("#breed_list").setSelection(valId, false);
	
	var cellValue = $('#breed_list').getCell(valId, 'breed_name');
    
    $('#breed').val(cellValue);
    
	validateElement('#manage_breed', '#breed', 'breed', 'breed_required', '.breed_error_1')
	validateElement('#manage_breed', '#breed', 'breed', 'breed_exist', '.breed_error_2')
	
}


Thank You,
Rich