$html_output .= '<div class="form-group">
<label><input type="radio" name="driver_type" value="society" checked required> Society</label>
<label><input type="radio" name="driver_type" value="entrepreneur"> Entrepreneur</label>
<label><input type="radio" name="driver_type" value="other"> Other</label>
</div>';
i tried to do it with script but didn't work
<script>
document.addEventListener('DOMContentLoaded', function() {
var driverTypeRadios = document.querySelectorAll('input[name="driver_type"]');
driverTypeRadios.forEach(function(radio) {
radio.addEventListener('change', function() {
if (this.checked) {
var myvalue = this.value;
console.log('Selected Driver Type:', myvalue);
// Send myvalue to PHP via AJAX
var xhr = new XMLHttpRequest();
xhr.open('POST', '<?php echo admin_url('admin-ajax.php'); ?>', true);
xhr.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded; charset=UTF-8');
xhr.onload = function() {
if (xhr.status >= 200 && xhr.status < 400) {
// Success - do something if needed
console.log('Response:', xhr.responseText);
} else {
// Error - handle errors if needed
console.error('Request failed:', xhr.statusText);
}
};
xhr.onerror = function() {
// Handle network errors
console.error('Network error occurred');
};
xhr.send('action=handle_selected_driver_type&myvalue=' + encodeURIComponent(myvalue));
}
});
});
});
</script>