Click here to Skip to main content
15,891,473 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
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:

JavaScript
<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

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


JavaScript
$( "#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[^]
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900