简体   繁体   中英

How can i filter data by checkbox check or uncheck

I have a few checkbox like below. and when one checkbox checked it must load result from mysql and when unchecked again it must load result without page refresh.

Almost it is same with http://www.facebook.com/find-friends/browser/

How can i do?

 <div class="tags">  <label><input type="checkbox" class="arts" /> Arts </label> <label><input type="checkbox" class="computers" /> Computers </label> <label><input type="checkbox" class="health" /> Health </label> <label><input type="checkbox" class="video-games" /> Video Games </label> </div>

您可以使用JavaScript和jQuery来执行此操作: http : //api.jquery.com/jQuery.get/

This is most easily accomplished using jQuery (as stated above). In general, you'll go through a series of 'find something' then 'do something' tasks. I'm no javascript expert, but my feeble attempt at the logic should get you started on the right path.

The jQuery logic will look something like this:

Hope this helps.

You need to use Ajax.

As people suggested, jQuery allows you to do this easily.

Example:

In a JavaScript file:

$.ajax({
  url: '/get-data',
  type: 'GET',
  data: { tags: anArrayOfCheckedCheckboxes }, // get the checked checkboxes the way you want
  complete: function(response) {
    // do what do you need with the response (display results for example)
  }
});

On PHP's side ( /get-data URL):

$tags = $_GET['tags'];
// get the results from the database
return json_encode($results);

您可以获取已选中复选框$('[name =” hobbies”:checked]')。val()的值,对于未选中复选框,可以使用$(“ input:checkbox:not(:checked)”)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM