Quantcast
Viewing all articles
Browse latest Browse all 17529

Send error message if user selects more than 2 times "yes" on one page - by: tpartner

As we have no clue what code you used to achieve that layout and functionality, it's hard to give constructive advice.

Having said that, I imagine you will need to put a listener on the radios and disable the unchecked ones when a maximum is reached. Something like this (untested):

<script type="text/javascript" charset="utf-8">
	$(document).ready(function(){
 
		var maxAllowed = {TOKEN:ATTRIBUTE_1};
 
		// Listener on the radios
		$('.yes-no input[type="radio"]').on('click', function(e) {
			// Reset the radios
			$('.yes-no input[type="radio"][value="Y"]').prop('disabled', false);
 
			// Test for max allowed 
			if($('.yes-no input[type="radio"][value="Y"]:checked').length == maxAllowed) {
				// If true, disable all unchecked "Yes" radios
				$('.yes-no input[type="radio"][value="Y"]:not(:checked)').prop('disabled', true);
			}
		});
	});
</script>

Viewing all articles
Browse latest Browse all 17529

Trending Articles