Click here to Skip to main content
14,336,280 members
Rate this:
Please Sign up or sign in to vote.
See more:
I am using jquery button to execute the ajax call to show data. I want to show some more data on same ajax call on clicking the checkbox.

What I have tried:

<pre> <This ajax success function is executed on button click

success: function(data) {
			
			var $metar=$(data).find("METAR");
			

			$metar.each(function(){

			var raw = $(this).find('raw_text').text();
    		  $("#ProfileList" ).append('<li>' +raw+ '</li>');
		    //<big>on checkbox click i want to show the station id</big>
		    $("#planned_checked").change(function() {
			if($("#planned_checked").prop('checked')) {
			var station_id = $(this).find('station_id').text();
			alert(station_id);
						
			});  //each function end
			
			
     }
	 
	 }); //ajax end
Posted
Updated 21-Mar-19 16:10pm

1 solution

Rate this:
Please Sign up or sign in to vote.

Solution 1

You can wrap the Ajax call in the checkbox change event. Here is an example.


$( "#check1" ).change(function() {
  var $input = $( this );
  
  if ($input.is( ":checked" )) {
  	//ajax call
  }
}).change();


Since you mentioned " same ajax call ", I would suggest place the Ajax call into a method so that it can be shared between the button and checkbox event.

.prop() | jQuery API Documentation[^]
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100