1

I am trying to get the custom query string value in the URL to get inserted into the default value in my html code. Need help getting the value to get inserted within my html code. I need it to take place of the; value="URL VALUE"

enter image description here

Above is a screenshot of the url with the custom query value that was pulled from the previous page's form submission.

<input type="text" id="myInput" onkeyup="myFunction(event)" placeholder="Search our library" title="Type in a name" value="URL VALUE">
sn22
  • 85
  • 2
  • 7
  • Possible duplicate of https://stackoverflow.com/questions/9870512/how-to-obtain-the-query-string-from-the-current-url-with-javascript – Jagdeep Singh Jul 02 '18 at 17:25

1 Answers1

0

you can use this piece of javascript code to get any parameter from url

var url = "http://www.example.com/index.php?myValue=384&login=admin"; // or window.location.href for current url
var captured = /myValue=([^&]+)/.exec(url)[1]; // Value is in [1] ('384' in our case)
var result = captured ? captured : 'myDefaultValue';
document.getElementById('myInput').value = result;
MajiD
  • 2,420
  • 1
  • 22
  • 32