I want an easy way to set a variable value equal to n when function(n) runs.
<a href="products.html" onclick="loadProdType(0)">Hovedkort</a>
<a href="products.html" onclick="loadProdType(1)">Prosessor</a>
<a href="products.html" onclick="loadProdType(2)">Arbeidsminne</a>
I have this piece of HTML code. And I want the loadProdType function to change the value of a variable prodCat according to loadProdType's value. I tried the code under with and witout localstorage.setItem(loadCat, j). The js document is linked and there are no linking errors cause other pieces of code runs as it should.
var loadCat = 0
function loadProdType(j){
loadCat = j}
How can I set loadCat's value equal to loadProdType's value/parameter.
Thanks in Advance.
Edit:
Unsure how to set local storage for this but what I want the code to do is the following:
- Change the value of variable
prodCat
according to the value of the onclick function. - Redirect to:
products.html
- When in
products.html
I run a piece of code that uses the prodCat value to choose a spesific index in an array.
All in all I just need to be able to change prodCat
on one page(to the value of a funcion or with a onclick) and have it saved on the next.
Last edit I'll create different functions for each onclick and try that with local storage.