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!

2 Answers 2

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" />
Sign up to request clarification or add additional context in comments.

Comments

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']?>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.