Answer the question
In order to leave comments, you need to log in
Is it possible, when processing the submit event of the form, to find out the entered data?
The form is in a react component.
Answer the question
In order to leave comments, you need to log in
class Example extends Component {
state = {
inputValue: '',
};
handleChange = e => {
const { name, value } = e.target;
this.setState({
[name]: value,
});
};
handleSubmit = e => {
e.preventDefault();
// получить состояние формы можно обратившись к this.state
};
render() {
const { inputValue } = this.state;
return (
<form onSubmit={this.handleSubmit}>
<input
name="inputValue"
value={inputValue}
onChange={this.handleChange}
/>
...
</form>
);
}
Of course you can!
Everything on the page can be pulled through JS. Whether it's a native request, like getElementById, or processing a pre-prepared state, or access via a ref link ...
ps the question is not the most correct, more details are needed.
Of course you can!
If pulled from a form, you will need to give the form a name.
So to pull data from the name field of the kek form, you will need to use the following code:var data = kek.name.value
On jQuery
$('form').on('submit', function() {
var data = {};
$('form input').each(function() {
data[$(this).attr('name')] = $(this).val();
});
});
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question