-4

What's wrong with my codes?

frame 1

<script type="text/javascript">
var Clicks = 0 ;
function AddClick(){
Clicks = Clicks + 1;
document.getElementById('CountedClicks').innerHTML =  Clicks ;
}
localStorage.setItem('Clicks');
</script>
</head>
Fish and Chips
<p align="right"> <input Type="BUTTON" VALUE="Order" onclick=" AddClick()"></p>

frame 2

<head>
<script type="text/javascript">
var loc = "";

function go() {
window.location.href = loc;
}
function set_loc(theURL) {
loc = theURL;
}
window.onload = function() {
            div = document.getElementById("CountedClicks");
            div.innerHTML=localStorage.getItem('variable');
        }
</script>
</head>
    <body>
    <div id="container" style="background-color:#8A4117;height:30%;width:98%;borde-radius:15px" >
You have ordered <span id="CountedClicks">0 </span> items.<br>
<p align="right"><input type=submit name="Submit" value="Checkout" onchange="set_loc('pay.html');" /></a></p>
</div>

I can't count the number of clicked buttons from another frame using this. *NOT MY OWN CODE

1 Answers1

2

You never write any data to local storage. You can't getItems that do not exist.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • I used this localStorage.setItem('Clicks'); But nothing happened. Is there still something wrong? – user2135437 Mar 07 '13 at 15:04
  • `setItem` takes **two** arguments and the string `'Clicks'` is not the same as the string `'variable'` – Quentin Mar 07 '13 at 15:07
  • I already changed variable to Clicks but the AddClick function still doesn't work. Although the value of the CountedClicks changed from 0 to 1 but not incrementing. – user2135437 Mar 07 '13 at 15:16