pkm
pkm

Reputation: 2783

Ajax request not starting

I have below html part

<div style="display:inline-block" class="seeker">
    <style>h2   {color: white;}</style>
        <form action="">
        <input type="checkbox" class="seek" id=CLOUD name="CLOUD" value="CLOUD"  >CLOUD &emsp;
        <input type="checkbox" class="seek" id=TESTING name="TESTING" value="TESTING"  >TESTING &emsp;
    </form>
</div>

and this as part of script

<script>
$('.seek').click(function(){
     alert("test");
     /*var value = document.getElementById(id).value;
     var endpoint = '/xyz/pqr/'
     var url = endpoint.concate(value)
     $.get(url, function(data){
         $("#testDIV").html(response);
           });*/
});

But on checking the checkbox the ajax call is not triggered any issue with code?

Upvotes: 0

Views: 64

Answers (3)

Rob M.
Rob M.

Reputation: 36511

$('.seek').on('change', function() {
   var checkedValues = $('.seek:checked').map(function(){
     return $(this).val();
   }).get();
   console.log("Changed: ", this.value, "to", this.checked)
   console.log(checkedValues);  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div style="display:inline-block" class="seeker">
    <style>h2   {color: white;}</style>
        <form action="">
        <input type="checkbox" class="seek" id=CLOUD name="CLOUD" value="CLOUD"  >CLOUD &emsp;
        <input type="checkbox" class="seek" id=TESTING name="TESTING" value="TESTING"  >TESTING &emsp;
    </form>
</div>

You should use the change event, not click for checkboxes:

$('.seek').on('change', function(event) {
     event.preventDefault();
     alert("test");
});

Upvotes: 1

Andriy
Andriy

Reputation: 15442

$.get in your post is within commented block, wrapped with /**/, just remove comment

Upvotes: 0

mthomp
mthomp

Reputation: 249

The first thing I noticed is that you are using $('#seek'). seek is a class so you should be using $('.seek') to select it.

jQuery uses the standard "CSS" selectors. so

# = ID
. = Class
[name='foo'] = Name
ect

Upvotes: 1

Related Questions