Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

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>
    );
  }
Comment

PREVIOUS NEXT
Code Example
Javascript :: jquery slideshow autoplay 
Javascript :: set exit node tor 
Javascript :: javascript simple hash 
Javascript :: js max array 
Javascript :: angular how to copy text with button 
Javascript :: legend on click use default chartjs 
Javascript :: animejs reduce the speed 
Javascript :: coderbyte first factorial solutions 
Javascript :: flatten json python 
Javascript :: queryselector in javascript 
Javascript :: js sort strings lowercase and uppercase 
Javascript :: mongoose update 
Javascript :: tinymce get plain text 
Javascript :: jspdf converted pdf save to server 
Javascript :: handling event in jsx 
Javascript :: for loop on object js 
Javascript :: puppeteer 
Javascript :: javascript remove required attribute 
Javascript :: define member in discord.js 
Javascript :: vue is undefined vue 3 vue.use 
Javascript :: using python with javascript 
Javascript :: axios defaults headers common 
Javascript :: javascript search after user stops typing 
Javascript :: javascript escape single quote 
Javascript :: function declaration and function definition in javascript 
Javascript :: flatlist only rendering 10 items 
Javascript :: chart js x axis data bar 
Javascript :: chrome block javascript alert 
Javascript :: react render for loop 
Javascript :: creatable select react 
ADD CONTENT
Topic
Content
Source link
Name
8+1 =