---
title: "How can I send the radio button value in PHP using JavaScript?"  
description: "How can I send the radio button value in PHP using JavaScript?"  
author: "Revati S Misra"  
published: 2023-08-29  
updated: 2023-09-02  
canonical: https://www.mindstick.com/forum/159726/how-can-i-send-the-radio-button-value-in-php-using-javascript  
category: "php"  
tags: ["javascript", "php", "radiobutton"]  
reading_time: 2 minutes  

---

# How can I send the radio button value in PHP using JavaScript?

How can I send the [radio button](https://www.mindstick.com/articles/12743/radio-button-in-android) [value](https://www.mindstick.com/articles/23219/an-optimized-description-adds-value-to-experience-and-in-turn-effectively-guest-posting-packages) in [PHP](https://www.mindstick.com/articles/12149/php-constant-and-php-variables) using [JavaScript](https://www.mindstick.com/articles/874/how-to-create-watermark-text-for-textbox-by-using-javascript)?

## Replies

### Reply by Aryan Kumar

Sure, I can help you with that.

To send the radio [button](https://www.mindstick.com/articles/63/how-to-add-button-in-datagridview-in-csharp-dot-net) value in PHP using JavaScript, you can use the `onchange` event. The `onchange` 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

```plaintext
// Get the radio button value.
var radioButtonValue = document.querySelector("input[name='my_radio_button']").value;

// Send the radio button value to PHP.
var xhr = new XMLHttpRequest();
xhr.open("POST", "/my_php_script.php");
xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send("radio_button_value=" + radioButtonValue);
```

In this code, the `radioButtonValue` variable is the value of the radio button that is selected. The `xhr` variable is an `XMLHttpRequest` object that is used to send the radio button value to PHP. The `send()` method of the `xhr` 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 simple `my_php_script.php` file:

PHP

```plaintext
<?php

// Get the radio button value.
$radioButtonValue = $_POST['radio_button_value'];

// Do something with the radio button value.
echo "The radio button value is " . $radioButtonValue;

?>
```

In this code, the `$_POST['radio_button_value']` variable is used to get the radio button value that was sent from JavaScript. The `echo` statement is used to print the radio button value to the browser.


---

Original Source: https://www.mindstick.com/forum/159726/how-can-i-send-the-radio-button-value-in-php-using-javascript

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
