All TalkersCode Topics

Follow TalkersCode On Social Media

devloprr.com - A Social Media Network for developers Join Now ➔

How To Get Value From URL In HTML Page

Last Updated : Jul 1, 2023

How To Get Value From URL In HTML Page

In this tutorial we will show you the solution of how to get value from URL in HTML page, sometimes, in some webpages we saw that there are some parameters that we fill our data in one webpage that are reused in next page with the help of URL.

The codes that we saw in URL are due to method get used in webpage. Let us understand how we can do that.

Step By Step Guide On How To Get Value From URL In HTML Page :-

Here, below we give you codes in html in which we used some codes which are used to get full URL from webpage and also the parameters that are used in webpage.

Before this we have to create a webpage so that after submission of this webpage we saw some values with parameters in our URL. Let do it.

<!DOCTYPE html>
      <html>
        <head>
          <title> Title of the document<title>
        </head>
          <body>
  <form method=”get”>
  Enter name
 <input type=”text” name=”fname”>
<br>
Enter your age in years
<input type=”number” name=”age” min=”0”>
 <input type=”submit” value=”submit”>
  </form>
</body>
</html>
  1. First, we write <! DOCTYPE html> which we used as an instruction to the web browser about what version of HTML file is written in.
  2. Secondly, the <html> tag is used to indicate the beginning of an HTML document.
  3. As above now <head> tag is used to contain information about web page. In this tag a <title> tag is used which helps us to specify a webpage title.
  4. Both <head> and <title> tags are Paired tags. So, both have </head> and </title> ending tags respectively.
  5. Thirdly, <body> tag is used to define the webpage body. All the contents to show on website are written here.
  6. Hence, here we create a webpage or say html page in which we use form tag to create form and inside form we give space for text field and other for number field.
  7. And then we create a submit button. Now, let us first get the full url and then its values of parameters - const queryString = window.location.search; console.log(queryString);
  8. Whereas this above code is used to get the value of full url and the code here given below is for the values of parameters which we want to get. const queryString = window.location.search; const urlParams = new URLSearchParams(queryString); const page_type = urlParams.get('page_type'); console.log(page_type);
  9. Hence, here above we used the codes in console of webpage you can also use this code to get the values form url.
  10. Now, it you want to get the values from url to webpage then you have to write the above code in php or html page rather than console. We hope that you understand the codes properly.
  11. At last, the <body> and <html> tags are closed with </body> and </html> respectively.

Conclusion :-

At last here in conclusion, we can say that with the help of this article we are able to get values from URL in html page. I hope this tutorial on how to get value from URL in HTML page helps you.