Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

react text input onchange

class NameForm extends React.Component {
  constructor(props) {
    super(props);
    this.state = {value: ''};
    this.handleChange = this.handleChange.bind(this);
    this.handleSubmit = this.handleSubmit.bind(this);
  }

  handleChange(event) {    this.setState({value: event.target.value});  }
  handleSubmit(event) {
    alert('A name was submitted: ' + this.state.value);
    event.preventDefault();
  }

  render() {
    return (
      <form onSubmit={this.handleSubmit}>
        <label>
          Name:
          <input type="text" value={this.state.value} onChange={this.handleChange} />        </label>
        <input type="submit" value="Submit" />
      </form>
    );
  }
}
Comment

react input text onchange target method

class App extends React.Component {
  constructor(props) {
    super(props);
    
    this.state = {
      data: 'Bound data...'
    }
    this.updateState = this.updateState.bind(this);
    
  };
  updateState(e) {
    this.setState({data: e.target.value});
  }
  render() {
    return (
    <>
        <input type="text" value = {this.state.data} onChange = {this.updateState} />
        <h4>{this.state.data}</h4>
        </>
             );
  }
}
        ReactDOM.render(
        <App />, document.getElementById('mountNode') );
Comment

onChange in react js

import React from "react";

function App() {
  function handleChange(event) {
    console.log(event.target.value);
  }

  return (
    <input
      type="text"
      name="firstName"
      onChange={handleChange}
    />
  );
}

export default App;
Comment

PREVIOUS NEXT
Code Example
Javascript :: reactjs hello world 
Javascript :: check if two rectangles overlap javascript canvas 
Javascript :: axios post 
Javascript :: what indexof in javascript 
Javascript :: react proxy 
Javascript :: leaflet each layer 
Javascript :: loop through array javascript 
Javascript :: how to autoload config files added in composer.json laravel 
Javascript :: regex optional whitespace characters 
Javascript :: Sort big numbers from an array in javascript 
Javascript :: convert to 24 hours format javasript 
Javascript :: does filter mutate array 
Javascript :: expo custom fonts 
Javascript :: how to filter out undefined keys from object in js 
Javascript :: react router dom v6 active link 
Javascript :: Javascript random password generator Exampe 
Javascript :: js array clone 
Javascript :: find inside iframe jquery 
Javascript :: how hide .html in url 
Javascript :: change data js 
Javascript :: js text to html 
Javascript :: how to separate thousands with comma in js 
Javascript :: join a list of strings into one string javascript 
Javascript :: electron disable scrollbar 
Javascript :: how to run commands in the command prompt using javascript 
Javascript :: js different 
Javascript :: tolocaledatestring format dd-mm-yyyy 
Javascript :: stop a function javascript 
Javascript :: js script 
Javascript :: npx http server 
ADD CONTENT
Topic
Content
Source link
Name
3+9 =