-1

I want to get value (TEXT) from URL to input from.

Example:

domain.com/page?code=123abc

I need to get 123abc paste automatically on input form with (code) id or name.

How I can do it with JS.

Thank you.

Need to use JavaScript

rez
  • 1
  • 3
  • I'm sure you can use `URLSearchParams` https://developer.mozilla.org/en-US/docs/Web/API/URLSearchParams – Zesty Dec 25 '22 at 18:15

1 Answers1

2

See URLSearchParams

const urlParams = new URLSearchParams(window.location.search);
const myParam = urlParams.get('myParam');

then set as .value of the input.

Ronnie Royston
  • 16,778
  • 6
  • 77
  • 91