7 Replies - 784 Views - Last Post: 11 November 2013 - 02:28 PM

#1 woodsmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-October 12

Question on resetting counter values.

Posted 06 December 2012 - 12:35 PM


<html>
 <head>
   <title> Die Rolls </title>
   <script type="text/javascript" src="http://balance3e.com/random.js">
   </script>
   <script type="text/javascript">
     function RollDice()
     // Assumes: die images are in http://balance3e.com/Images
     // Results: displays 2 random die rolls & keeps a count in rollSpan
     {
       
       var roll1, roll2;
       
       roll1 = RandomInt(1, 6);
       roll2 = RandomInt(1, 6);
       
       
       document.getElementById('die1Img').src = 
         'http://balance3e.com/Images/die' + roll1 + '.gif';
       document.getElementById('die2Img').src = 
         'http://balance3e.com/Images/die' + roll2 + '.gif';
       
       document.getElementById('rollSpan').innerHTML=
         parseFloat(document.getElementById('rollSpan').innerHTML) + 1;
    
    if (roll1==roll2) {document.getElementById('doubleSpan').innerHTML=
    parseFloat(document.getElementById('doubleSpan').innerHTML) + 1;
    
     }
     }
   </script>
 </head>

 <body>
   <div style="text-align:center"> 
     <p>
       <img id="die1Img" alt="die image"
            src="http://balance3e.com/Images/die1.gif">
       <img id="die2Img" alt="die image"
            src="http://balance3e.com/Images/die1.gif">
     </p>
     <input type="button" value="Click to Roll" onclick="RollDice();">
     
     <hr>
     <p>
       Number of rolls: <span id="rollSpan">0</span>
       Number of doubles: <span id="doubleSpan">0</span>
     
     </p>
   </div>
 </body>
</html>



This code works perfectly except im looking for a way to reset the counter variables back to zero without reloading the page what would be the best way to go about this I have looked through some books and tried searching the web but havent found anything Its probally something extremly simple im just not thinking about.

Is This A Good Question/Topic? 0
  • +

Replies To: Question on resetting counter values.

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,975
  • Joined: 08-June 10

Re: Question on resetting counter values.

Posted 06 December 2012 - 12:37 PM

it is indeed dead simple: document.getElementById('rollSpan').innerHTML = 0;
Was This Post Helpful? 0
  • +
  • -

#3 woodsmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-October 12

Re: Question on resetting counter values.

Posted 06 December 2012 - 12:39 PM

I dont see how that helps I need to still have a functioning counter and I need a button I can click to just reset both counters setting that value to 0 would ruin the whole script.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3470
  • View blog
  • Posts: 9,975
  • Joined: 08-June 10

Re: Question on resetting counter values.

Posted 06 December 2012 - 12:43 PM

canít follow you there. you donít have a variable for either counter.

and that you need a button (or similar) to do the resetting I took for granted knowledge.

btw. you could also output the counter in a text field, then a reset-type button should also work.
Was This Post Helpful? 0
  • +
  • -

#5 woodsmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-October 12

Re: Question on resetting counter values.

Posted 06 December 2012 - 12:46 PM

You've completly lost me.
Was This Post Helpful? 0
  • +
  • -

#6 woodsmc  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 15
  • Joined: 04-October 12

Re: Question on resetting counter values.

Posted 06 December 2012 - 08:53 PM

Thank you dorm I feel stupid was seriously the easiest thing ever I dont know why I tried to complicate it I seem to always be doing that.
Was This Post Helpful? 0
  • +
  • -

#7 Dtk276  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 11-November 13

Re: Question on resetting counter values.

Posted 11 November 2013 - 01:48 PM

What did you do to reset both values? I'm having the same exact situation.
Was This Post Helpful? 0
  • +
  • -

#8 andrewsw  Icon User is online

  • Fire giant boob nipple gun!
  • member icon

Reputation: 3101
  • View blog
  • Posts: 10,378
  • Joined: 12-December 12

Re: Question on resetting counter values.

Posted 11 November 2013 - 02:28 PM

As Dormilich explained:

document.getElementById('rollSpan').innerHTML = 0;    // for both:
document.getElementById('doubleSpan').innerHTML = 0;

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1