How to add value to hidden input field using ES6

  javascript

I would like to take this jQuery statement and change it to be ES6. This currently looks for the item introducer and if it exists we add it to a hidden input field.

if (sessionStorage.getItem("introducer") === null) {
  console.log('nope');
} else {
  console.log('exists');
  $("input[name=Origin]").val("Introducer");
}

I have tried the following but console errors on .value

if (sessionStorage.getItem("introducer") === null) {
  console.log('nope');
} else {
  console.log('exists');
  document.getElementsByName("input[name=Origin]").value("Introducer");
}

Any suggestions or guidance would be much appreciated.

Many thanks in advance!

Source: Ask Javascript Questions

LEAVE A COMMENT