Answers for "how to redirect a form to another page when we submitted a form in react js"

0

how to redirect a form to another page when we submitted a form in react js

onSubmitHandler = (e) => {
    e.preventDefault();
    this.setState({
      showName: true
    });
    if(this.state.showName){
      // submitting the form conditionally with javascript
      document.getElementById("nameForm").submit();
    }
  }
  render() {
    return (
      <div>
        <form
          onSubmit={this.onSubmitHandler}
          id="nameForm"
          action="https://google.com"
          method="GET"
        >
          <label>Enter the Name</label>
          <input type="text"
            name="firstName" onChange={this.inputHandler} value=
            {this.state.firstName} />
          <button type="submit" onClick={this.onSubmitHandler}>Submit</button>
          {this.state.showName && <p>"FirstName: " {this.state.firstName}</p>}
        </form>
      </div>
    );
  }
Posted by: Guest on September-30-2021

Code answers related to "how to redirect a form to another page when we submitted a form in react js"

Code answers related to "Javascript"

Browse Popular Code Answers by Language