Johny Funny Johny Funny - 17 days ago 7
Javascript Question

Save and show input value in session storage

I have input number and button with text on subpage.

<input id="quantity" type="number">


I want to save value from input and show on button.

<a id="button2" data-role="button">You have "value" coins</a>


How i can do it?

Answer

If I understood well,

Here is solution

$('#quantity').keyup(function(){
    var quantity=$(this).val();
    sessionStorage.setItem('quantity',quantity);
    $('a').text('You have ' +  sessionStorage.getItem('quantity') +'  coins');
});