Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

form handling in react

function MyForm() {
  const handleSubmit = (event) => {
    event.preventDefault();

    const data = new FormData(event.currentTarget);
    const values = Object.fromEntries(data.entries());

    if (!Number(values.age)) {
      alert('Your age must be a number');
      return;
    }

    console.log('submitting', values);
  };

  return (
    <form onSubmit={handleSubmit}>
      <h1>Hi!</h1>

      <p>Enter your name:</p>
      <input type="text" name="username" />

      <p>Enter your age:</p>
      <input type="text" name="age" />

      <br /><br />
      <input type="submit" />
    </form>
  );
}
Comment

PREVIOUS NEXT
Code Example
Javascript :: local reference in angular 
Javascript :: angular component 
Javascript :: The document.createElement() Method 
Javascript :: react native spinkit 
Javascript :: axios get request 
Javascript :: javascript call stacks 
Javascript :: show json data in table using javascript 
Javascript :: materal ui react range slider 
Javascript :: compare date value in javascript 
Javascript :: javascript sort strings of object 
Javascript :: react-bootstrap-table2-editor 
Javascript :: how to lose overflow in js without hidden 
Javascript :: promise js 
Javascript :: react native border radius not working ios 
Javascript :: polyfill for call 
Javascript :: check if the collection exists in mongodb database mongoose 
Javascript :: trimend in javascript 
Javascript :: click tester 
Javascript :: react-timeago npm 
Javascript :: Button get specific input hidden value JQuery 
Javascript :: js foreach mdn 
Javascript :: Finding Value of Promise With Then Syntax 
Javascript :: update reducer 
Javascript :: trigger keydown event javascript 
Javascript :: .map method 
Javascript :: Nuxt.js + Electron 
Javascript :: property binding angular 
Javascript :: clean-webpack-plugin clearing dist folder 
Javascript :: Fibonacci , fibo 
Javascript :: fs readfile promise 
ADD CONTENT
Topic
Content
Source link
Name
2+1 =