mercredi 5 avril 2017

Display value from checkbox in console.log

Well this is probably an easy question but I've been figure this one out. I would like to display the value of a checkbox in the console.log so I can use it to fire a AJAX call. But the values of every checkbox is the same (the first one).

I have spent some time on google and I for what I read there, I should put the checkbox in an array. But I can't seem to get it to work. Here is my code at the moment.

HTML

<!-- Custom taxonomy checkboxes -->
     <?php
        $taxonomy = 'locatie';
        $queried_term = get_query_var($taxonomy);
        $terms = get_terms($taxonomy, 'slug='.$queried_term);
            if ($terms) {
              foreach($terms as $term) {
                $name = $term->name;
                echo "<div class='col-xs-12 col-sm-12 col-md-2 col-lg-2'>
                    <form id='location'>
                        <input class='checkIt' type='checkbox' value='".$name."' name='location' id='".$name."_id'>&nbsp;&nbsp;".$name."
                    </form>
                </div>";                             
              }
        }
    ?>
<!-- /Custom taxonomy checkboxes -->

jQuery

<script>
jQuery(document).ready(function($) {
    $('.checkIt').change(function(e) {
        var value = $('.checkIt').val();
        $.post('../wp-content/themes/mysite/includes/search-team.php',{value:value}, function(data){
            $('#search_results_team').hide().fadeIn(1100);
             $("#search_results_team").html(data);
             console.log(value);
        });
    });
});
</script>

Everything works, even the AJAX call, except the console.log output so I can't sent different values trough the AJAX call. Any help would be really nice!




Aucun commentaire:

Enregistrer un commentaire