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.
Page 3 of 3 FirstFirst 123
Results 31 to 34 of 34
  1. #31
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    I keep trying to reply here, but my posts are not being accepted.

  2. #32
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Exclamation

    Quote Originally Posted by chads View Post
    I keep trying to reply here, but my posts are not being accepted.
    Well, that blows that theory out of the water!

    Primary problem with your last code post is that id assignments MUST be unique.
    Fix all your id="clicked" settings if you want to address them individually.

  3. #33
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,146
    Thanks
    39
    Thanked 505 Times in 499 Posts

    Lightbulb

    You still have problems with miss-matched <td>...<td> tags.
    You should try running it through an HTML validation program to see other problems.

    Still a bit unclear about the clicked counts.
    For example, clicking 0.50 to add one to clicked0 value?
    Click -0.50 adds another to the clicked0 value or should it be subtract 1?
    Following code does the latter. Change logic to your needs (which are still unclear to me).

    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
    <head>
    <title>Pocket Money</title>
    <meta http-equiv="Content-Type" content= "text/html; charset=utf-8">
    <meta name="viewport" content="width=device-width">
    <meta name="viewport" content= "initial-scale=1.0, user-scalable=yes">
    <style type="text/css">
     @media screen { body { font-size: 16px } }
     @media screen, print { body { line-height: 1.2 } }
     div { width:300px; float:left; }
     p { clear:both; }
    </style>
    <!-- Modified for: http://www.codingforums.com/showthread.php?p=1331197#post1331197 -->
    </head>
    <body>
    <form id="myform" method="post" onsubmit="return false" name="myform">
    <div style=" text-align: centre; text-indent: 0px; padding: 0px 0px 0px 0px; margin: 0px 0px 0px 0px;">
    <table width="100%" border="0" cellpadding="2" cellspacing="10" style="background-color: #045FB4;">
    <tr valign="top">
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.50" onclick="bump(this.value);linkClick('clicked0','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.50" onclick="bump(this.value);linkClick('clicked0','-')"></td>
    <td style="border-width : 0px;"><input id="clicked0" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.50" onclick="bump(this.value);linkClick('clicked1','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.50" onclick="bump(this.value);linkClick('clicked1','-')"></td>
    <td style="border-width : 0px;"><input id="clicked1" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="1.00" onclick="bump(this.value);linkClick('clicked2','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-1.00" onclick="bump(this.value);linkClick('clicked2','-')"></td>
    <td style="border-width : 0px;"><input id="clicked2" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.25" onclick="bump(this.value);linkClick('clicked3','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.25" onclick="bump(this.value);linkClick('clicked3','-')"></td>
    <td style="border-width : 0px;"><input id="clicked3" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.50" onclick="bump(this.value);linkClick('clicked4','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.50" onclick="bump(this.value);linkClick('clicked4','-')"></td>
    <td style="border-width : 0px;"><input id="clicked4" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.25" onclick="bump(this.value);linkClick('clicked5','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.25" onclick="bump(this.value);linkClick('clicked5','-')"><v>
    <td style="border-width : 0px;"><input id="clicked5" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.10" onclick="bump(this.value);linkClick('clicked6','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.10" onclick="bump(this.value);linkClick('clicked6','-')"></td>
    <td style="border-width : 0px;"><input id="clicked6" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.10" onclick="bump(this.value);linkClick('clicked7','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.10" onclick="bump(this.value);linkClick('clicked7','-')"></td>
    <td style="border-width : 0px;"><input id="clicked7" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="1.00" onclick="bump(this.value);linkClick('clicked8','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-1.00" onclick="bump(this.value);linkClick('clicked8','-')"></td>
    <td style="border-width : 0px;"><input id="clicked8" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="0.25" onclick="bump(this.value);linkClick('clicked9','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-0.25" onclick="bump(this.value); linkClick('clicked9','-');"></td>
    <td style="border-width : 0px;"><input id="clicked9" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="1.50" onclick="bump(this.value); linkClick('clicked10','+')"></td>
    <td style="border-width : 0px;"><INPUT type="image" src="" value="-1.50"  onclick="bump(this.value); linkClick('clicked10','-'); "></td>
    <td style="border-width : 0px;"><input id="clicked10" size="3"  value="0"></td>
    </tr>
    <tr>
    <td style="border-width : 10px;">
    <td style="border-width : 0px;">
    <input type="text" width: 100px; height: 100px; readonly id="totaljobs" value="0" 
     style="width:60px; height:30px;font-size:18pt;color:black; border-style:12; weight:bold; background-color: #CED8F6;">
    <button onclick="clearTally()">Clear</button> 
    </tr>
    </table>
    </div>
    <script type="text/javascript">
      function bump(jobs) {
        var total = Number(document.getElementById('totaljobs').value);
        total += Number(jobs);
        document.getElementById('totaljobs').value = total.toFixed(2);
        persistTally();
      }
      function clearTally() {
        document.getElementById('totaljobs').value = '0.00';
        for (var i=0; i<12; i++) { document.getElementById('clicked'+i).value = 0; }
        persistTally();
      }
    
      function linkClick(IDS,dir){
        var clicks = Number(document.getElementById(IDS).value);
        if (dir == '+') { document.getElementById(IDS).value = clicks+1; }
                   else { document.getElementById(IDS).value = clicks-1; }
      } 
    /* * Indicate if this browser supports local storage.  */
      function html5StorageSupported() {
         return ('localStorage' in window) && window['localStorage'] !== null;
      }
    
    /* * Provide indication on web page of whether this browser supports local storage.  */
      function initializeTally() {
        if ( html5StorageSupported() ) {
          if (localStorage['tally.total'] == undefined) { clearTally(); } else { loadTally(); }   // altered original code here
        } else { alert('Local storage is not supported'); }
      }
    
    /* * Save tally total to local storage.  */
      function persistTally() {
         if (html5StorageSupported()) { 
           var tally = document.getElementById("totaljobs").value;
           var storageIndex = "tally.total";
           localStorage[storageIndex] = tally;
         } else { alert("Cannot save to local storage because it's not supported."); }
      }
    
    /* * Load tally total from local storage.  */
      function loadTally() {
         if (html5StorageSupported()) {
           document.getElementById('totaljobs').value = localStorage["tally.total"];
         } else { alert("Cannot load from local storage because it's not supported."); }
      }
    
    window.onload = function() { initializeTally(); }
    
    </script></form>
    </body>
    </html>

  4. Users who have thanked jmrker for this post:

    chads (05-19-2013)

  5. #34
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    7
    Thanks
    3
    Thanked 0 Times in 0 Posts
    HI Jmrker,

    That is exactly what I was looking for:

    this is the bit I couldn't work out how to write:
    Code:
    linkClick('clicked2','+')"
    Thank you


 
Page 3 of 3 FirstFirst 123

Posting Permissions

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