0

I am looking to automatically enter information into an HTML via adding parameters in the url (for example google.com?param=test, where "test" will automatically be entered into the google search box). This would ideally be possible without having to modify the code whatsoever, and it could target an with a specific class, id or name.

Any help would be greatly appreciated, thanks!

jonahclarsen
  • 101
  • 6

2 Answers2

1

Use the function getParameterByName(name, url) from this answer to get querystring values.

Then, use JavaScript and/or jQuery to modify the input values. Example in jQuery:

<script>
    var param = getParameterByName('param'); // test
    $("#myId").val(param);
</script>
<input id="myId" type="text" />
chakeda
  • 1,551
  • 1
  • 18
  • 40
1

You can't do that by only using HTML, because it's a markup language. To access the URL query parameters I would suggest using for example JavaScript:

<script>
 var url_string = window.location.href; // Current page URL
 var url = new URL(url_string);
 var param = url.searchParams.get("param");
 console.log(c);
</script>

In php that would be:

<?=$_GET['param']?>
gabriella-varga
  • 371
  • 2
  • 4
  • 15