# onClick Updating a variable on the page

**URL:** https://forum.kirupa.com/t/onclick-updating-a-variable-on-the-page/317395
**Category:** web dev
**Created:** [December 18, 2010, 10:42pm UTC](https://forum.kirupa.com/t/onclick-updating-a-variable-on-the-page/317395 "2010-12-18T22:42:41Z")
**Posts on this page:** 1
**Page:** 1

<div class="post-metadata">

### Author: ![jw06](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@jw06](https://forum.kirupa.com/u/jw06)
#### Post date: [December 18, 2010, 10:42pm UTC](https://forum.kirupa.com/t/onclick-updating-a-variable-on-the-page/317395/1 "2010-12-18T22:42:41Z")

</div>

Hello…

I am trying to figure out how to change text on my page after an onclick event occurs.

I am tracking a variable, lets say myVar, that when a certain button is clicked it updates the variable and then updates some text on the page. I don’t use JS very much, but this looks like the best way to do it with my setup; however I am open to any suggestions.

Right now I have this function for tracking when an item is clicked. The alert is just for testing purposes to make sure its tracking.

```auto

var tpoints = 40;
var dpoints = 0;

function adjustPoints()
{
	tpoints--;
	dpoints++;
	
	alert('tpoints: ' + tpoints);
        
	return false;
}

```

Here is my link that I am counting clicks:

```auto

<a href="#" onmouseover="ajax_showTooltip(window.event,'../tooltip/poll.php?n=<?php echo $ttable[$ttier][$tcolumn];?>',this);return false" onmouseout="ajax_hideTooltip()">

```

and then I want to display my JS variable tpoints at some point in the page but keep it updated as the link is clicked.

Any thoughts into the best way to accomplish this?
