How to get parameter value to javascript variable? As an example:
<a href="page.php?id=10&value='hello'">click me</a>
Here, I want to get the key named id, and its value hello to assign them to a javascript variable. How to do it?
How to get parameter value to javascript variable? As an example:
<a href="page.php?id=10&value='hello'">click me</a>
Here, I want to get the key named id, and its value hello to assign them to a javascript variable. How to do it?
You may use the URLSearchParams class.
const url_params = new URLSearchParams(window.location.search);
const id = url_params.get('id');
console.log(id);
"page.php?id=10&value='hello'", which is an invalid URL search param input. You'll either need some reliable way to get rid of page.php, or build the full URL and use the built-in URL object.