

			Programs in HTML5
7. Example for localStorage.
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
<script>
function showbalance()
{
	if(localStorage.balance)
	{
		document.getElementById("amt").value = localStorage.balance;
	}
	else
	{
		localStorage.balance=0;
	}
}
function deposit()
{
	if(localStorage.balance)
	{
		localStorage.balance = Number(localStorage.balance)                     
          + Number(document.getElementById("amt").value);
	}
	else
	{
		localStorage.balance=0;
	}
}
function withdraw()
{
	if(localStorage.balance)
	{
		localStorage.balance = Number(localStorage.balance)
         - Number(document.getElementById("amt").value);
	}
	else
	{
		localStorage.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 the previous balance.
Developed by