Jump to content

vAriable Scope


george
 Share

Recommended Posts

Basically I have this

<html><head><script type="text/javascript"> <!--   var iterator = 1;function calculate() {	iterator++;}   --></script></head><body><form><input type="button" onclick="calculate();" value="Press Me"  /></form></body></html>

I want to be able to increment the variable "iterator" each time I click "Press Me".

Link to comment
Share on other sites

Unless i'm missing something here your code is fine :) If you put an alert in the function you will see the value incrementingfunction calculate() { alert(iterator); iterator++;}Hope this helps :)

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...