react checkbox onChange
<input
checked={checkboxValue}
onChange={() => setCheckboxValue(!checkboxValue)}
type="checkbox"
/>class Reservation extends React.Component {
constructor(props) {
super(props);
this.state = {
isGoing: true,
numberOfGuests: 2
};
this.handleInputChange = this.handleInputChange.bind(this);
}
handleInputChange(event) {
const target = event.target;
const value = target.type === 'checkbox' ? target.checked : target.value;
const name = target.name;
this.setState({
[name]: value });
}
render() {
return (
<form>
<label>
Is going:
<input
name="isGoing" type="checkbox"
checked={this.state.isGoing}
onChange={this.handleInputChange} />
</label>
<br />
<label>
Number of guests:
<input
name="numberOfGuests" type="number"
value={this.state.numberOfGuests}
onChange={this.handleInputChange} />
</label>
</form>
);
}
}
Also in JavaScript:
- convert csv to json powershell code
- mapping a pojo with json via gson
- how to get the square root in js
- javascript remove first space in string
- javascript substring messes emoji
- js alert
- javascript update text in div
- React looping hooks to display in other hook
- find length of longest string in array javascript
- javascript minute and second to convert seconds
- javascript create array of objects with map
- how to check if 2 images are touching js
- input set variable angular
- create a html table dynamically using javascript
- javascript object total
- angular http client
- count number of times an element is occuring in an array in javascript
- indexing string in javascript
- how to import jquery in js file
- transpose of the matrix in javascript
- returned data has p tags react
- find year javascript
- react lifecycle
- javascript get srollwidth