Alright, before i start, i’m very new to javascript, i started teaching myself a few days ago (and took a break from it for 2 of those days). Anyway, i’m having some trouble with a pretty simple problem.
I want to have multiple variables, all connected to a ‘pool’. You may add or subtract from each one, which would subtract or add to the pool, respectively. Also, you cannot add any more to any of the variables if the pool is empty. It would look sort of like this:
Pool: 34
Alpha: (3) + –
Beta: (0) + –
Gamma: (21) + –
Delta: (9) + –
The pluses and minuses are images with an onclick event, so eventually i can animate the buttons and customize them how i want with photoshop and flash.
I was hoping there would be a simple way to output an integer variable right into the page, without having it in a form box, but have yet to find a syntax to do that. That’s why i’ve been using the <span> element. However, my function ignores the pool being equal or less than 0 because it doesn’t recognize the element as an integer, even when i use parseInt… i’m stumped. Here’s some basic code:
[code]
<html>
<head>
<script type=”text/javascript”>
function AddDP(a)
{
var temp = parseInt(a);
if(a <= 0)
{
return(0);
}
else
{
var DP = document.getElementById(“DP”);
DP.innerHTML = parseInt(DP.innerHTML) – 1;
return(1);
}
}
function SubDP(a)
{
var temp = parseInt(a);
if(temp <= 0)
{
return(0);
}
else
{
var DP = document.getElementById(“DP”);
DP.innerHTML = parseInt(DP.innerHTML) + 1;
return(-1);
}
}
</script>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″><style type=”text/css”>
<!–
body {
background-color: #000000;
}
body,td,th {
color: #FFCC33;
}
–>
</style></head>
<body>
Pool: <span id=’DP’>60</span>
<br>
<br>
Chill <img onclick=’
var Chill = document.getElementById(“Chill”);
var DP = document.getElementById(“DP”);
Chill.innerHTML = parseInt(Chill.innerHTML) + AddDP(Chill);’
src=Plus.jpg>
<img onclick=’
var Chill = document.getElementById(“Chill”);
var DP = document.getElementById(“DP”);
Chill.innerHTML = parseInt(Chill.innerHTML) + SubDP(Chill);’
src=Minus.jpg>
(<span id=’Chill’>0</span>)
</body>
</html>