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 in HTML by Ashwini
• 1,160 points
24 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 in HTML by Tejashwini
• 1,660 points
8 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 in HTML by Tejashwini
• 1,660 points
19 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 in HTML by Tejashwini
• 1,660 points
14 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 in HTML by Ashwini
• 1,160 points
8 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 in HTML by Deepak
• 760 points
15 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,280 points
18,989 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,500 points
407 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,740 points

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