Get the query string value and display it in my html page

0 votes

I can see the query string values that I had entered on the previous page after being sent to the home.html page.

Home.html?FirstName=dd&LastName=ee&smtButton=Submit

And am getting the result:

firstname = undefined
lastname = undefined
age = undefined

Could anyone help me to solve this?

JS:

function getParams() {
    var idx = document.URL.indexOf('?');
    var params = new Array();
    if (idx != -1) {
        var pairs = document.URL.substring(idx + 1, document.URL.length).split('&');
        for (var i = 0; i < pairs.length; i++) {
            nameVal = pairs[i].split('=');
            params[nameVal[0]] = nameVal[1];
        }
    }
    return params;
}

params = getParams();
firstname = unescape(params["firstname"]);
lastname = unescape(params["lastname"]);
age = unescape(params["age"]);
document.write("firstname = " + firstname + "<br>");
document.write("lastname = " + lastname + "<br>");
document.write("age = " + age + "<br>");
Jul 21, 2022 in HTML by Ashwini
• 5,430 points
1,423 views

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In HTML

0 votes
0 answers

What's the right way to decode a string that has special HTML entities in it?

Let's say I submit a service request ...READ MORE

Jul 8, 2022 in HTML by Tejashwini
• 3,820 points
299 views
0 votes
0 answers
0 votes
0 answers

How to get the entire document HTML as a string?

Is there a way in javascript to ...READ MORE

Jun 3, 2022 in HTML by Tejashwini
• 3,820 points
295 views
0 votes
0 answers

how to create a HTML5 video element without it being shown in the page?

how is it possible to dynamically create ...READ MORE

Jul 5, 2022 in HTML by Tejashwini
• 3,820 points
267 views
0 votes
0 answers

How to GET background color of a particular portion on the html page

I used Gradient to set the color ...READ MORE

Jul 26, 2022 in HTML by Ashwini
• 5,430 points
1,097 views
0 votes
1 answer

trying to align html button at the center of the my page

For example: HTML <div> <button>Submit</button> </div> CSS button { margin:auto; ...READ MORE

answered Aug 4, 2022 in HTML by Deepak
• 980 points
314 views
0 votes
1 answer

How to store an array in localstorage?

Localstorage only supports Strings. So you can ...READ MORE

answered Jul 1, 2019 in Others by sunshine
• 1,300 points
22,438 views
0 votes
1 answer
0 votes
0 answers

Anyone can help me out to understand the semantic of (document.getElementBYId("demo").innerHTML="Hello") ?

Hello guys, Can Someone helps me to find ...READ MORE

Jan 17, 2020 in Web Development by anonymous
• 37,510 points
751 views
+1 vote
1 answer

What is the relationship between angularjs Scope with controller/view?

Let us consider the below block: <div ng-controller="emp"> ...READ MORE

answered Jan 20, 2020 in Web Development by Niroj
• 82,880 points

edited Jan 21, 2020 by Niroj 814 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP