user198989
user198989

Reputation: 4665

Select option onclick function works in FF but not in Chrome

I can successfully change the chart option in firefox, but it doesn't work in chrome (no errors). I have read almost all of the topics about this issue, but none of them worked for me. What is the correct way to catch when user selects options ?

enter image description here

<select id="sortby2">
  <option id="byweek" value="date">7 days</option>
  <option id="by14" value="spent">14 days</option>
  <option id="bymonth" value="clicks">30 days</option>
</select>

$("#by14").OnClick(function(){
$.ajax({
    type: "POST",
    url: "chartdata.php",
    data: 'by14=on',datatype:"html",  async: false,
    success: function(d){
    $('.cantent').html(d);      
    }       
});
});

Upvotes: 1

Views: 2685

Answers (3)

colestrode
colestrode

Reputation: 10658

Listen for a "change" event on the select element. It's best to use the jQuery on() function to register it:

$("#sortby2").on('change', function(){
    if($(this).val() === 'spent') {
        $.ajax({
            type: "POST",
            url: "chartdata.php",
            data: 'by14=on',datatype:"html",  async: false,
            success: function(d){
                $('.cantent').html(d);      
            }       
        });
    }
});

Upvotes: 1

Adil
Adil

Reputation: 148110

You probably need to use change() instead of click event.

$("#sortby2").change(function(){

  if($(this).find('option:selected')[0].id != 'by14')
           return;

  $.ajax({
        type: "POST",
        url: "chartdata.php",
        data: 'by14=on',datatype:"html",  async: false,
        success: function(d){
        $('.cantent').html(d);      
        }       
    });
});

Upvotes: 2

PranitG
PranitG

Reputation: 121

Use $("#by14").click not $("#by14").onclick

Upvotes: 0

Related Questions