Bladephp: Now with 7+ codeigniter, php, and laravel project 7+ php project From $18/Year From Rs. 1000/Year

How to trigger jQuery change event in Checkbox

by
Category:javascript
javascript jquery html
How to trigger jQuery change event in Checkbox

You need to trigger the change event, .trigger('change'), so that event knows that a change took place.

They can be fired manually, however, with the .trigger() method. A call to .trigger() executes the handlers in the same order they would be if the event were triggered naturally by the user.

JavaScript Code

$('#typedetransport').on('change', function(){
	var value = $(this).val();
	if(value == 'Professionnel' || value == 'Scolaire')
	{
		$("#returnbox").prop("checked", true);
		$("#returnbox").trigger("change");
	}
	else
	{
		$("#returnbox").prop("checked", false);
		$("#returnbox").trigger("change");
	}
});

 Automatic Change Look

$('#returnbox').on('change', function(){
	this.value = this.checked ? 1 : 0;
	if(this.checked) {
		$('#date_return').prop('required',true);
		$('#time_return').prop('required',true);

	}
	else
	{
		$('#date_return').val('');
		$('#time_return').val('');
		$('#date_return').prop('required',false);
		$('#time_return').prop('required',false);					
	}
});

0 Comments


Html code work in comment box


Related Post