Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    javascript problem

    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.

  • #2
    Banned
    Join Date
    Sep 2003
    Posts
    3,620
    Thanks
    0
    Thanked 0 Times in 0 Posts

  • #3
    Regular Coder
    Join Date
    Jun 2004
    Posts
    565
    Thanks
    0
    Thanked 18 Times in 18 Posts
    Code:
    <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?

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    yes thats what I wanted, big thanks =)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •