-1

This is my Form:

<form id="locationsearch">
  <label for="locationsearch">Location:</label>
  <input type="search"  name="locationsearch" id="searchValue"/>
</form>

I wish to get the value of the search input .

Altough I can access the search input's value like this:

const locationSearch = document.getElementById("locationsearch");
  locationSearch.onsubmit = function (e) {
    const searchValue = document.getElementById("searchValue");
    console.log("search value", searchValue.value);
    e.preventDefault();
  };

But Can we access it using the 'e' parameter? For e.g I tried this which is not working:

const locationSearch = document.getElementById("locationsearch");
  locationSearch.onsubmit = function (e) {
    console.log("search value", e.target.input['search'].value);
    e.preventDefault();
  };

Does this work in react only?

kob003
  • 810
  • 1
  • 8
  • 14
  • 1
    The event is the parameter - from the `.target`, you have the form. From there you can access a child with `querySelector` (flexible for any selector string), or `.elements`, or `.` – CertainPerformance May 16 '22 at 04:45

0 Answers0