Search
 
SCRIPT & CODE EXAMPLE
 

JAVASCRIPT

how to access form values in react

handleSubmit = (event) => {
  event.preventDefault();
  console.log(event.target[0].value)
}
Comment

get react form input data, How get form input data in react

import { useForm } from "react-hook-form";

export default const SimpleForm = () => {
  
  // For Multiple input
  const { register, handleSubmit, reset } = useForm();

  const onSubmit = (data) => {
      const newData = new FormData();
      newData.append("userid", currentUser._id);
      newData.append("username", currentUser.name);
      newData.append("comments", data.comments);
      // In Console get Json Formatedata You can fatch 
      // Post To the database to save 
      console.log([...newData]); 
    
      // Reset the Form 
      reset();
  }

  return (
      <form onSubmit={handleSubmit(onSubmit)} className="form">
          <input type="text" {...register("comments")} />
      </form>
  )


}



 // 2nd Options 
<form onSubmit={handleSubmit(onSubmit)} className="form">
	<input type="text" name="username"/>
</form>
                
const onSubmit = (event) => {
  event.preventDefault();
  console.log(event.target.elements.username.value) // from elements property
  console.log(event.target.username.value)          // or directly
}

Comment

PREVIOUS NEXT
Code Example
Javascript :: luxon timestamp 
Javascript :: how to add button react native app.js 
Javascript :: send url by whatsapp in javascript 
Javascript :: mat checkbox change event in angular 7 
Javascript :: Select options of Select2 control based on values using Jquery 
Javascript :: npm install global vs local 
Javascript :: this keyword in javascript medium 
Javascript :: how to split text into array javascript 
Javascript :: js onclick change styles 
Javascript :: How to check if array includes a value from another array in JavaScript 
Javascript :: Warning: Prop `className` did not match. Client and server rendered different classes . 
Javascript :: react useeffect async javascript 
Javascript :: how to render a new page in node js through express 
Javascript :: mongoose find by and delete 
Javascript :: alphabet as array javascript 
Javascript :: sort array of objects by string property value 
Javascript :: javascript array flat 
Javascript :: puppeteer get attribute 
Javascript :: iframe chrome console 
Javascript :: today date javascript 
Javascript :: alphabet only in jquery 
Javascript :: laravel array to js 
Javascript :: react forwardref 
Javascript :: select2 find option by value 
Javascript :: check if any property of object is null javascript 
Javascript :: how to do radio button validation in jquery 
Javascript :: express js boilerplate 
Javascript :: js event preventdefault continue 
Javascript :: fetch 
Javascript :: node js catch any errors 
ADD CONTENT
Topic
Content
Source link
Name
6+3 =