onSubmit Client Script - return false not working

Laurie Marlowe1
Kilo Sage

Hello,

We have a variable set with an onSubmit client script for catalog items that checks various accounting detail information before an item is put into the shopping cart.  I had to make changes to the script so it would work on the service portal.  The script had a "getXMLWait()" which I had to change to "getXML()".  So every thing is working fine except in the callback function, the "return false" is not stopping the submission.  Here is the code.

The if statement with the alert('here i am') displays the alert, but it doesn't seem to stop the submission, and still puts the item in the cart.  What is causing this?

 

function callBack(response){
		
		var valResponse = response.responseXML.documentElement.getAttribute("answer");
		alert(valResponse);
		
		
		valResponse = valResponse.split(',');
		alert(valResponse[0]+'---'+valResponse[1]);
				
		if(valResponse[0] == '200'){
			alert("enter"+valResponse[0] );
			if(valResponse[1] == 'V'){
				alert("validation passed");
				
			}else{
				alert("Please enter correct Accounting Details");
				return false;
			}
		}
		
		if(valResponse[0] == '500'){
			if(valResponse[1] != 'V'){
				alert('here is am');
				alert("Please enter correct Accounting Details");
				return false;
			}
		}
		
		else{
			alert('in last else');
			alert("Please enter correct Accounting Details");
			return false;
		}
		
	}
	
}

Thank you,

Laurie

 

17 REPLIES 17

Dubz
Mega Sage

Hi,

 

Since you can't use getXMLWait() the script is running asynchronously so the onSubmit function is completing before the glide ajax is done doing it's thing. I don't think there's a simple solution to this, you might have to move your validation into an onChange script.

 

Cheers

Dave

Hi David,

I tried changing it to an onChange script and it works!  BUT, it is dependent on a mandatory variable changing, and then having to reset it.  Not very elegant.  Or is it?  I'm an intermediate coder, so not sure.

Thanks,

Laurie

 

 

I think the best solution would be an onChange client script. Have the callback function blank out the field if the server response is invalid. That way since the variable is mandatory and has been blanked out, it won't let you submit.

If you really have to have it onSubmit, do an onChange client script that sets a flag in g_scratchpad to true or false in your callback function, then have your onSubmit check the flag, so there's no AJAX in your onSubmit.

Oh ugh!  It still puts it in the cart.