Reputation: 4665
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 ?
<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
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
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