admin管理员组文章数量:1122846
$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>
本文标签: phpCapture the Selected Radio Button Value between two files in wordpress theme
版权声明:本文标题:php - Capture the Selected Radio Button Value between two files in wordpress theme 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1736301545a1931210.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论