0

thanks for reading this post.

I need help with passing value to next page, but in my case, there is not only one value, but there is also more than one value to choose for and if a user clicks on specific card value then the button with id=save will save the value of the card

 (function (global) {
    document.getElementById("save").addEventListener("click", function () {
        global.localStorage.setItem("mySharedData", document.getElementById("input").value);
    }, false);
}(window));
// If user click the button on this card, it will automatically save card1 value to local storage
<div class="card">
<input type="hidden" id="input" value="card1"></input>
  <div class="card-body">
    This is some text within a card body.
  </div>
<button id="save" href="nextpage.php" class="btn">Next</button>
</div>

// If user click the button on this card, it will automatically save card2 value to local storage
<div class="card">
<input type="hidden" id="input" value="card2"></input>
  <div class="card-body">
    This is some text within a card body.
  </div>
<button id="save" href="nextpage.php" class="btn">Next</button>
</div>

I've tried Sharing a variable between multiple html pages it works for passing only 1 value. In the end, this is what I wanted: user clicks on a specific card -> save the input value of the card -> display the saved value on the next page.

I am still learning about developing a website/coding. Please go easy on me, thank you very much!

utf-alnka
  • 11
  • 2
  • 1
    I think you're onto the right idea by using `localStorage`. You should be able to create multiple items using `localStorage` and access them that way. – Adam Feb 14 '19 at 14:55
  • I see you are using php on the server side? Why dont you pass the variables via http requests? – Jasper Lichte Feb 14 '19 at 14:59
  • @Adam yes, but in this case, I wanted only the clicked value is displayed on the next page. Maybe it will be better if I use sessionStorage for it. – utf-alnka Feb 14 '19 at 15:01
  • @JasperLichte well yes i was actually thinking to use that, but I used jquery refresh on every card button. I was thinking the shortcut way to display card data without making specific variables for every card button. I have around 50 cards for this project. – utf-alnka Feb 14 '19 at 15:04

0 Answers0