first question here. I’m building a record store website in HTML5 where one page (store.html) displays all the albums and below each one there is a Buy Now button with a link to buy.html
<div class="item goth rock folk cd">
<div class="card-izotop-img">
<img src="img/vinyl/wolfe_abyss.jpg" alt="Chelsea Wolfe - Abyss">
</div>
<div class="card-izotop-info">
<h6>Chelsea Wolfe - Abyss</h6>
<h5>€ 25</h5>
<a href="vinyl/buy.html">Buy Album</a>
</div>
</div>
The buy.html page will be common for all albums in this page. What I’m trying to do is somehow pass info from the album clicked (on store.html page) to the buy.html page. So if someone clicks on the above example he will get text saying: You want to buy “Chelsea Wolfe – Abyss” at “25” euros
while someone else who clicks on a different album will get that album’s info. Note that I’m not using a form, most answers I found here use forms as a solution.
Since this is an independent record store I want to avoid monthly fees and commissions to Shopify or Paypal etc so I’m trying a simple solution. If you can point me towards a direction I can find a way to work this out. Thank you
3
Answers
Well yes, the first option to pass information from one page to another will be a form.
Because you don’t want to use that, there is a second method which is passing information as a query string in the URL you will be hitting.
Point to keep in mind while using query string:
While passing spaces or special characters, prefer encoding the values before passing them in URL.
There is a JavaScript function encodeURIComponent() to encode them because spaces,etc can be unsafe when passed in URL directly.
I think you should use PHP+MYSQL to do it.
You should:
Show list of albums and links with record number parameter
Fox example:
<a href="vinyl/buy.php?a=1">Buy album</a>
<a href="vinyl/buy.php?a=2">Buy album</a>
Select a row from database with record number you get from URL.
You will get the recond number using code
$record_number=@$_GET[a];
and use $record_number to select album info from database
If you are looking for an HTML5 solution, one approach is to use HTML5 localStorage.
You can
set
name-value pairs inlocalStorage
(which will remember them on every page across the site).When you want to retrieve the values, you can
get
them back fromlocalStorage
, and populate anobject
with them.From then on (on that page), you can interrogate the
object
.Example: