Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

Radio button in react

  const [gender,setgender]=useState()

 const handlegender=(e)=>{
    setgender(e.target.value)
  }
 

 
 <form>
        
        <div>
          <label>Gender</label>
          <input type="radio" name="gender" value="male" onChange={handlegender} />
          Male
          <input type="radio" name="gender" value="Female" onChange={handlegender}/>
          Female
        </div>
      </form>
Comment

how to use radio buttons in react class-based components

class App extends React.Component {
  
  setGender(event) {
    console.log(event.target.value);
  }
  
  render() {
    return ( 
      <div onChange={this.setGender.bind(this)}>
        <input type="radio" value="MALE" name="gender"/> Male
        <input type="radio" value="FEMALE" name="gender"/> Female
      </div>
     )
  }
}

ReactDOM.render(<App/>, document.getElementById('app'));
Comment

react input radio button


function App() {
  return (
    <div>
      <label className="radio">
  <input name="radio" type="radio" checked/>
  <span>Awesome</span>
</label>
<label className="radio">
  <input name="radio" type="radio" />
  <span>Cool</span>
</label>
    </div>
  );
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: how to get element by id in node js 
Javascript :: return last two values of array in javascript 
Javascript :: js remove value input 
Javascript :: bootstrap dropdown doesnt work with angular 12 
Javascript :: javascript form post json data 
Javascript :: js script 
Javascript :: get current location url javascript 
Javascript :: csv to json python 
Javascript :: javascript get item in array by id 
Javascript :: how to merge 2 object array by the same key with lodash 
Javascript :: email regex pattern input css 
Javascript :: jquery mobile or desktop 
Javascript :: read xlsx file in angular 5 
Javascript :: how to clear state in react hooks 
Javascript :: ajax current url 
Javascript :: convert string to unicode javascript 
Javascript :: js click anchor 
Javascript :: round decimal js 
Javascript :: modal.hide not working 
Javascript :: js how to round up 2 decimal places 
Javascript :: check if object has method javascript 
Javascript :: delete a node in dom javascript 
Javascript :: yup number string 
Javascript :: angular ng default scss 
Javascript :: javascript tofixed is not a function 
Javascript :: click counter in js 
Javascript :: how to count specific letters in string js 
Javascript :: add array to array javascript 
Javascript :: lookup in mongodb array 
Javascript :: generate an array of random numbers javascript 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =