In my code I have a radio and would like to get the selected option in a variable in my jquery function.
Button Input:
<?php
echo $this->Form->input('attendance_status_id', array(
'type' => 'radio',
'options' => $attendance_statuses,
'div' => array('id' => 'attendance-statuses', 'class' => 'attendance_statuses'),
'legend' => '',
'label' => true
));
?>
Script where I want to receive it:
$("#attendance-statuses").change(function(){
var obs = $('input[name = attendance_status_id]:checked').serialize();
console.log(obs);
$.ajax({
type: 'post',
data:
{obs,
obsEntity: 1
},
url: "<?php echo Router::url('/observations/observation_options'); ?>",
success:function(dados){
dados = JSON.parse(dados);
var $el = $("#obs-select");
$('#obs-select option:gt(0)').remove();
$.each(dados, function(value,key) {
$el.append($("<option></option>")
.attr("value", value).text(key));
});
}
});
});