Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

clear input file html react

e.target.value = null;
Comment

reset input react

const App = () => {
  const [message, setMessage] = useState('');
  return (
    <div>
      <input
        type="text"
        value={message}
		onChange={(event) => {
          setMessage(event.target.value);
        }}/>

      <button 
		onClick={() => {
          alert('check')
          // clear input value
          setMessage('');
        }}>
          Clear field
      </button>
    </div>
  );
};
Comment

reset form input react

cancelCourse = () => { 
  document.getElementById("create-course-form").reset();
}

render() {
  return (
    <form id="create-course-form">
      <input />
      <input />
      ...
      <input />
    </form>
  );
}
Comment

react class component input text with clear button

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

PREVIOUS NEXT
Code Example
Javascript :: javascript Accessing Object Methods 
Javascript :: JavaScript Add Methods to a Constructor Function Using Prototype 
Javascript :: javascript Update Values of Properties 
Javascript :: javascript Symbols are not included in for...in Loop 
Javascript :: javascript Arrow Function as an Expressio 
Javascript :: zigale assefa 
Javascript :: javascript typeof operator returns function 
Javascript :: freecodecamp javascript basic step quoting string 
Javascript :: electron InitializeSandbox() called with multiple threads in process gpu-process. 
Javascript :: JavaScript HTML DOM Node Lists 
Javascript :: find the missing number javascript 
Javascript :: json syntax 
Javascript :: javascript get days difference between two dates 
Javascript :: fingerprint 
Javascript :: get page scrolling amount js 
Javascript :: Cntrlsss:$.Control-Ai 
Javascript :: phaser add frames to existing animation 
Javascript :: phaser tween timescale 
Javascript :: Pretty-Print JSON within Neovim 
Javascript :: how to map elements from 1st object react js 
Javascript :: hot reload nestjs 
Javascript :: get elements by class name wildcard 
Javascript :: DataTables warning: table id=datatable - Ajax error 
Javascript :: add line break in innerhtml 
Javascript :: react native ios firebase push notifications not working 
Javascript :: hide and show div using javascript with example 
Javascript :: random number between 1 and 10 javascript 
Javascript :: map && arrow function in javascript 
Javascript :: gitea 
Javascript :: best way to filter table in angular 
ADD CONTENT
Topic
Content
Source link
Name
9+9 =