1

at index.html

function pay(id)
{
    localStorage.thing = id;
}
<button type="button" id="opt1" onclick="pay(this.id)" onclick="window.location.href = 'payment.html'"></button>

at payment.html

window.onload = function() 
{
    def();
};

function def()
{
    document.getElementById('card').innerHTML = localStorage.thing;
}
<h1 id="card"></h1>

my main goal is to define button's id from payment.html page through element but when i click the button nothing's working.

  • 1
    You have two `onclick`-handlers on the button. If you really need both, then make it into a function. – Zeth Nov 25 '22 at 18:45
  • @Zeth +1. I'm leaving an upvote because I wouldn't have come up with the idea of defining multiple onclick attributes. I had to check if it actually works. Spoiler: it doesn't. – TwistedOwl Nov 25 '22 at 18:52
  • @Zeth The 2 onclicks are both restrictions? By that means I need to know how can I transfer to a new page using a function. – if_statement Nov 25 '22 at 19:01
  • @if_statement In HTML you can only have an attribute specified once, not multiple times. – slhck Nov 25 '22 at 19:14

1 Answers1

0

Try and change the first part to this:

function pay(id)
{
    localStorage.thing = id;
    window.location.href = 'payment.html'
}

And the markdown to this:

<button type="button" id="opt1" onclick="pay(this.id)">
  Button text
</button>
Zeth
  • 2,273
  • 4
  • 43
  • 91