Query string example in javascript

How to get all URL parameters with the query string?

Query string URL parameters need when we jump current page to another page then we use Or we need query string when the required value from the current URL. The very important thing is the when getting URL value then decodes a URI component after then use param name as given below example. Query string parameters and value we get in an easy way with this demo.


<!DOCTYPE html>
<html lang="en">

    <title>Query String in javascript</title>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

        <input type="text" name="Name" id="Name">
        <input type="text" name="phone" id="phone">
        <input type="hidden" value="" id="yourId1">
        <input type="hidden" value="" id="yourId2">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        jQuery(function () {
            var getUrlParameter = function getUrlParameter(sParam) {
                var sPageURL = decodeURIComponent(window.location.search.substring(1)),
                    sURLVariables = sPageURL.split('&'),
                for (i = 0; i < sURLVariables.length; i++) {
                    sParameterName = sURLVariables[i].split('=');

                    if (sParameterName[0] === sParam) {
                        return sParameterName[1] === undefined ? true : sParameterName[1];
            var param1Value = getUrlParameter("paramName1");
            var param2Value = getUrlParameter("paramName2");


No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.