

Programs in HTML5
8. Example for sessionStorage.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
function showbalance()
{
if(sessionStorage.balance)
{
document.getElementById("amt").value = sessionStorage.balance;
}
else
{
sessionStorage.balance=0;
}
}
function deposit()
{
if(sessionStorage.balance)
{
sessionStorage.balance = Number(sessionStorage.balance)
+ Number(document.getElementById("amt").value);
}
else
{
sessionStorage.balance=0;
}
}
function withdraw()
{
if(sessionStorage.balance)
{
sessionStorage.balance = Number(sessionStorage.balance)
- Number(document.getElementById("amt").value);
}
else
{
sessionStorage.balance=0;
}
}
</script>
</head>
<body>
Amount:<input type="text" id="amt">
<br><button type="button" onClick="showbalance()">Show</button>
<button type="button" onClick="deposit()">Deposit</button>
<button type="button" onClick="withdraw()">Withdraw</button>
</body>
</html>
Output :Amount:
Perform Deposit, Withdraw and Show balance. Later close the browser and open again check the balance. It will show '0' balance.
Developed by