Back to all resources
URL parameters
regular expressions

Set Hidden Input Value From URL Parameters

By Corey Moen
This JavaScript code defines a function getUrlParameter that retrieves the value of a specified parameter from the URL's query string. It uses regular expressions to locate the parameter and decode its value. The code also includes a conditional block that checks if the URL contains a "name" parameter. If it does, it retrieves the value using the getUrlParameter function and sets it as the value of an HTML element with the ID "name".