0

I'm trying to make an alert when somebody is entering his name. But it always says undefined... How can I fix that?

const handleSubmit = async(event) => {
  event.preventDefault();
  const name = event.target.name.value;
  alert(`Hi ${name}!`);
};
<form onSubmit={handleSubmit}>
  <input type="text" name="textinput" minlenght="1" placeholder="Wassup?"></input>
  <button type="submit">send</button>
</form>
juliomalves
  • 21,997
  • 12
  • 75
  • 81
Knocklive
  • 35
  • 4
  • 1
    Please note that not only is a closing `` tag not required, it doesn't exist and should *never* be there; an `` is a void element, and contains no children (similarly with `
    `, `
    `, ``...)
    – David Thomas May 02 '22 at 13:28
  • 2
    Does this answer your question: [Get form data in ReactJS](https://stackoverflow.com/questions/23427384/get-form-data-in-reactjs)? You need to use the `input`'s `name` attribute to access it, i.e. `event.target.textinput.value`. – juliomalves May 02 '22 at 15:55

0 Answers0