How to Submit Forms and Save Data with React.js
class UserForm extends React.Component {
constructor(props) {
super(props);
this.state = {username: ''};
this.handleChange = this.handleChange.bind(this);
this.handleSubmit = this.handleSubmit.bind(this);
}
handleChange(event) {
this.setState({username: event.target.value});
}
handleFormSubmit(event) {
console.log('username: ' + this.state.username);
event.preventDefault();
}
render() {
return (
<form onSubmit={this.handleFormSubmit}>
<label>
Name:
<input type="text" value={this.state.username} onChange={this.handleUsernameChange} />
</label>
<input type="submit" value="Submit" />
</form>
);
}
}handleInputChange(event) {
const value = event.target.value;
const name = event.target.name;
this.setState({
[name]: value
});
}
Also in JavaScript:
- video js toggle play pause
- navigating programatically react
- how get parent element javascript
- jquery get all select options
- jquery make readonly textbox
- print random string from an array to screen in javascript
- await on observable
- math.random js
- array find javascript
- how to clear array in javascript
- how to check the extension of a file in javascript
- set navigation drawer to open by default react native
- jquery get each row in table
- laravel csrf token ajax post
- js remove json value duplicates
- install node js 14
- angular directive example
- angular material upload file
- use jsx html
- reduce method in javascript array of bjects
- react get data attribute from element
- change color by java scribt
- how to export csv file in angularjs
- npm react router 6.0.0-alpha.2