How can I send the radio button value in PHP using JavaScript?
How can I send the radio button value in PHP using JavaScript?
33029-Aug-2023
Updated on 02-Sep-2023
Home / DeveloperSection / Forums / How can I send the radio button value in PHP using JavaScript?
How can I send the radio button value in PHP using JavaScript?
Aryan Kumar
02-Sep-2023Sure, I can help you with that.
To send the radio button value in PHP using JavaScript, you can use the
onchange
event. Theonchange
event is triggered when the value of an element changes.The following code shows how to send the radio button value in PHP using JavaScript:
JavaScript
In this code, the
radioButtonValue
variable is the value of the radio button that is selected. Thexhr
variable is anXMLHttpRequest
object that is used to send the radio button value to PHP. Thesend()
method of thexhr
object is used to send the radio button value to PHP.The
my_php_script.php
file can be used to process the radio button value. The following code shows a simplemy_php_script.php
file:PHP
In this code, the
$_POST['radio_button_value']
variable is used to get the radio button value that was sent from JavaScript. Theecho
statement is used to print the radio button value to the browser.