...

View Full Version : javascript problem



daemon
07-01-2004, 06:59 PM
I want a countdown feature that starts at 30, and is reduced with the values I select with 2 different + - button options, example:

Points left: 25

Strenght [ + ] [ - ] : 3 points

Stamina [ + ] [ - ] : 2 points

and finally im gonna post the values given to Strenght and Stamina to 2 column in my mysql database. So Im looking for some help how to make this happen, or links to scripts that are similar.

Willy Duitt
07-01-2004, 07:33 PM
:confused:

dumpfi
07-01-2004, 10:32 PM
<html>
<head>
<script type="text/javascript">
function stats() {
this.stats = new Array("free", "strength", "stamina");
this.free = 30;
this.strength = 0;
this.stamina = 0;
this.inc = function(stat) {
if(this.free) {
this[stat]++;
this.free--;
}
this.update();
}
this.dec = function(stat) {
if(this[stat]) {
this[stat]--;
this.free++;
}
this.update();
}
this.update = function() {
for(var i = 0; i < this.stats.length; i++) {
document.getElementsByName(this.stats[i])[0].value = this[this.stats[i]];
}
}
}

</script>
<style>
a { text-decoration:none; color:#000000; }

</style>
</head>
<body onload="stats = new stats()">
<form onSubmit="return (!stats.free)">
Points left: <input type="text" name="free" value="30" size="1" readonly>
<br>
Strength [ <a href="javascript:stats.inc('strength')">+</a> ] [ <a href="javascript:stats.dec('strength')">-</a> ] : <input type="text" name="strength" value="0" size="1" readonly>
<br>
Stamina [ <a href="javascript:stats.inc('stamina')">+</a> ] [ <a href="javascript:stats.dec('stamina')">-</a> ] : <input type="text" name="stamina" value="0" size="1" readonly>
<br>
<input type="submit" value="submit">
</form>
</body>
</html>

Is this what you're looking for?

daemon
07-02-2004, 02:12 AM
yes thats what I wanted, big thanks =)



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum