JavaScript | Know the value of GET parameters from URL
In order to know the parameters, those are passed by the “GET” method, like sometimes we pass the Email-id, Password, and other details. For that purpose, We are using the following snippet of code.
Example-1: This example get the value of “a” parameter from the URL.
<!DOCTYPE html> <html> <head> <title> JavaScript | Know the value from GET parameters </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <button onclick="myGeeks()"> Click here </button> <p id="GFG_down" style="color:green;"> </p> <script> function myGeeks() { var GFG_url_string = "https://ide.geeksforgeeks.org/login.php?a=GeeksForGeeks&b;=100&c;=Computer Science portal for Geeks"; var GFG_url = new URL(GFG_url_string); var c = GFG_url.searchParams.get("a"); var p_down = document.getElementById("GFG_down"); p_down.innerHTML = c; } </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before clicking on the button:
-
After clicking on the button:
Example:This example get the value of all the parameters from the URL.
<!DOCTYPE html> <html> <head> <title> JavaScript | Know the value from GET parameters </title> </head> <body style="text-align:center;"> <h1 style="color:green;"> GeeksForGeeks </h1> <button onclick="myGeeks()"> Click here </button> <p id="GFG_down" style="color:green;"> </p> <script> function myGeeks() { var GFG_url_string = "https://ide.geeksforgeeks.org/login.php?a=GeeksForGeeks&b;=100&c;=Computer Science portal for Geeks"; var GFG_url = new URL(GFG_url_string); var a = GFG_url.searchParams.get("a"); var b = GFG_url.searchParams.get("b"); var c = GFG_url.searchParams.get("c"); var p_down = document.getElementById("GFG_down"); p_down.innerHTML = a + "<br>" + b + "<br>" + c; } </script> </body> </html> |
chevron_right
filter_none
Output:
-
Before clicking on the button:
-
After clicking on the button:
Recommended Posts:
- JavaScript | Function Parameters
- Convert URL parameters to a JavaScript Object
- How to declare the optional function parameters in JavaScript ?
- JavaScript | Passing parameters to a callback function
- How to serialize an object into a list of URL query parameters using JavaScript ?
- How to get parameters from a URL string in PHP?
- Introduction to JavaScript Course | Learn how to Build a task tracker using JavaScript
- How to compare two JavaScript array objects using jQuery/JavaScript ?
- JavaScript Course | Understanding Code Structure in JavaScript
- JavaScript Course | Data Types in JavaScript
- JavaScript Course | Conditional Operator in JavaScript
- JavaScript Course | Printing Hello World in JavaScript
- JavaScript Course | Logical Operators in JavaScript
- JavaScript Course | Loops in JavaScript
- JavaScript Course | Functions in JavaScript
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.



