Gabriele Ferro Home

How to get URL variables

After I finally figured out how to send a POST request to the back-end, the last functionality required by the fifth OpenClassRooms project is to show a confirmation page that:

  • thanks the buyer;
  • shows the total to pay;
  • shows the order ID number.

Day 51: 26 September 2020

**Today’s Progress:**

Assume that our query string in the address bar is in the form:

https://www.website.com/page.html?orderid=mY-0rD3r-1D&firstname=myname&total=500

Using the substr() method on windows.location.search property, we will take the part of the string starting from the question mark (excluded).

URLSearchParams is an interface that defines utility methods to work with the query string of a URL.

For example, using the get() method we can parse out specific values.

In this case for each value of our query string, we create a text node and then with typical DOM manipulations, we retrieve the HTML element and we append the text node to it.

**Thoughts:**

I have passed the half of the #100DaysOfCode challenge, and if I look back I realize that I have learned a lot of things.

Disclaimer:
Actually, I should have been on day #83 since I program at least 2 hours a day. Every day.

But let's be honest and realistic: What would be the interest on my part to write an "article" where I list all the tests I have done without success?

Would it be interesting from the point of view of the potential reader or the future me to reread a list of the mistakes I made?

Writing every two days on a blog is already a real challenge in itself. If I add that I work for 7 hours and also that I write code for an average of 4 hours, the challenge becomes titanic.

It takes me about an hour to write a stupid article in English.

That's why I write every two days on the blog and I don't consider the previous day for the purpose of the challenge.

We would get bored and lose time unnecessarily.

**Link to tweet:**

[twitter-follow screen_name='20Gabriele20']

February 2024
MTWTFSS
 1234
567891011
12131415161718
19202122232425
26272829 

Archives

Gabriele Ferro Home
Copyright © Ferro Gabriele. All rights reserved.