/    Sign up×
Community /Pin to ProfileBookmark

store global values within function calls

Hi!

I have some functions that are called from html with “onClick”.
Now I need global variables but I can not pass or store them, because I have no real “programm”, only a couple of functions.

In other words: I have to increment a variable each time a function is called, but because the function is called from html I can not pass a global variable.

What can I do?
Can anybody help me?

to post a comment
JavaScript

4 Comments(s)

Copy linkTweet thisAlerts:
@Mr_JMar 12.2005 — Do you mean like this.

This will increment variable count each time the function is called

<script type="text/javascript">

<!--

count=0

function test(){

count++

alert("Count = "+count)

}

//-->

</script>

<a href="#null" onclick="test()">Count</a>
Copy linkTweet thisAlerts:
@langhaarauthorMar 12.2005 — It's as simple as that?

Thanks a lot!!!

I'm going to test it!
Copy linkTweet thisAlerts:
@Mr_JMar 12.2005 — I've added an alert to the above code so that you can see the count increment
Copy linkTweet thisAlerts:
@langhaarauthorMar 12.2005 — I already modified my code and it worked fine!

I needed this to number tags, which are dynamicaly created, in order to create buttons at specified places.

Bye ?
×

Success!

Help @langhaar spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.19,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...