I have a set of radio buttons which are loaded in via AJAX once a user has been selected. They have the option to have their access set to Yes or No depending if it is required or not. When the button is clicked the active class is applied and when i get the value of the checked item it returns the expected value.
The problem i am having is that the change event and the click event, neither of them will fire when the button is clicked?
HTML:
<div class="col-md-4">
<div class="btn-group" data-toggle="buttons" style="width:100%">
<label class="btn btn-default <?php if($access['has_access']){?> active <?php } ?>" style="width:50%">
<input type="radio" name="<?=$access['id']?>" id="option1" value="1" <?php if($access['has_access']){?> checked <?php } ?>>Yes
</label>
<label class="btn btn-default <?php if(!$access['has_access']){?> active <?php } ?>" style="width:50%">
<input type="radio" name="<?=$access['id']?>" id="option2" value="0" <?php if(!$access['has_access']){?> checked <?php } ?>>No
</label>
</div>
</div>
JS:
$(document).on('click', 'input[type="radio"]', function(){
var data = {};
data.access_id = $(this).attr('name');
data.value = $(this).val();
data.user_id = $('input[name="user_id"]').val();
$.ajax({
url: '/ajax/change_access.php',
type: 'POST',
cache: false,
data: data,
dataType: 'JSON',
headers: {"cache-action":"no-cache"}
}).done(function(data){
console.log('here');
}).fail(function(data){
console.log("error");
});
});
I have tried changing the target to just input but this has no affect on radio buttons but is triggered by text inputs. Could be missing something obvious but unable to see it, any help would be much appreciated.