How to set name and value in React Radio Button

13 Nov 20263 minutes to read

Use the name attribute to group React Radio Button components as mutually exclusive options. When grouped React Radio Buttons are submitted with a form, only the value attribute of the checked React Radio Button is sent to the server—retrieved using the shared name attribute. React Radio Buttons that are disabled or unchecked do not submit their values.

In the example below, the payment method “Credit / Debit Card” is in the checked state. When the form is submitted, only this checked React Radio Button’s value will be sent to the server.

import { enableRipple } from '@syncfusion/ej2-base';
import { RadioButtonComponent, ButtonComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';
enableRipple(true);
// Name and Value attribute in form submit.
function App() {
    return (<form>
      <ul>
          <li><RadioButtonComponent name="payment" value="credit/debit" label="Credit /Debit card" checked={true}/></li>

          <li><RadioButtonComponent name="payment" value="netbanking" label="Net Banking"/></li>

          <li><RadioButtonComponent name="payment" value="cashondelivery" label="Cash On Delivery"/></li>

          <li><RadioButtonComponent name="payment" value="others" label="Others"/></li>

          <li><ButtonComponent isPrimary={true}>Submit</ButtonComponent></li>
      </ul>
    </form>);
}
export default App;
ReactDom.render(<App />, document.getElementById('radio-button'));
import { enableRipple } from '@syncfusion/ej2-base';
import { RadioButtonComponent, ButtonComponent } from '@syncfusion/ej2-react-buttons';
import * as React from 'react';
import * as ReactDom from 'react-dom';

enableRipple(true);

// Name and Value attribute in form submit.
function App() {
  return (
    <form>
      <ul>
          <li><RadioButtonComponent name="payment" value="credit/debit" label="Credit /Debit card" checked={true} /></li>

          <li><RadioButtonComponent name="payment" value="netbanking" label="Net Banking" /></li>

          <li><RadioButtonComponent name="payment" value="cashondelivery" label="Cash On Delivery" /></li>

          <li><RadioButtonComponent name="payment" value="others" label="Others" /></li>

          <li><ButtonComponent isPrimary={true}>Submit</ButtonComponent></li>
      </ul>
    </form>
  );
}
export default App;
ReactDom.render(<App />, document.getElementById('radio-button'));