Results 1 to 8 of 8

Thread: counting

  1. #1
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    81
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default counting

    I'm trying to make a scoreboard (with statistics) for a sportsclub.
    At the moment the page is crowded with buttons - for every player a button for every stats-category.
    Now I would like to have only the players numbers or names on button and another row of buttons for each stat. To get the input i would have to hit a players button and next a stat button.

    let's say the players buttons are "pl01" and "pl02" and the stats "s1" and "s2"
    the stats would appear on screen as "pl01_s1", "pl01_s2", "pl02_s1" and "pl02_s2"

    so if i would hit button "pl01" and next "s1" then the stat "pl01_s1" would be added with 1.

    Is this possible with javascript? if so, can anyone give me an example?

  2. #2
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    <html>
    <head>
    <script type="text/javascript" lang="Javascript">
    var nplayers = 2;
    var nstats = 2;
    var stats = new Array ();
    //Predefine stats
    for (var i = 1; i <= nplayers; i = i + 1) {
    for (var j = 1; j <= nstats; j = j + 1) {
    stats ["p" + i + "s" + j] = 0;
    }
    }
    var pbutton = null;
    var sbutton = null;
    var check = function () {
    if (pbutton != null && sbutton != null) {
    stats ["p" + pbutton + "s" + sbutton] = stats ["p" + pbutton + "s" + sbutton] + 1;
    alert ("p" + pbutton + "s" + sbutton);
    pbutton = null;
    sbutton = null;
    }
    }
    </script>
    </head>
    <body>
    <div onclick="pbutton = 1; check ();">Player 1</div><br/>
    <div onclick="pbutton = 2; check ();">Player 2</div><br/>
    <div onclick="sbutton = 1; check ();">Stat 1</div><br/>
    <div onclick="sbutton = 2; check ();">Stat 2</div><br/>
    </body>
    </html>

    That worked for me. Add that script, you can change nplayers to the number of players you have, and nstats to the number of stats you have. Add onclick="pbutton = 1; check ();" to player buttons but 1 is whatever player, and onclick="sbutton = 2; check ();" to stat buttons where 2 is the stat number. I hope it works.

  3. #3
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    81
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Thanks, i'm going to try this, but it'll take some time to integrate everything, cause the individual stats (16 per player, 18 players) need to be put into team-totals, etc...
    I'll let you know if it worked

  4. #4
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Opse, it doesn't yet display the stats. If you want, I could write that part too.

  5. #5
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    81
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    the script works, but how do i get the stats in a table?
    let's say the 2 stats are points and assists and the players names are mike and john.
    when i push button "mike" and next button "points" then i would like to see the onscreen table change, adding 1 point to mike's total.

  6. #6
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Smile

    Code:
    var nplayers = new Array ("Player 1","Player 2");
    var nstats = new Array ("Stat 1","Stat 2");
    var stats = new Array ();
    var tableHTML = "";
    //Predefine stats
    tableHTML += "<tr><td style='background-color: grey;'></td>";
    for (var j = 1; j <= nstats.length; j = j + 1) {
    tableHTML += "<td>" + nstats [j - 1] + "</td>";
    }
    tableHTML += "</tr>";
    for (var i = 1; i <= nplayers.length; i = i + 1) {
    tableHTML += "<tr><td>" + nplayers [i - 1] + "</td>";
    for (var j = 1; j <= nstats.length; j = j + 1) {
    tableHTML += "<td id ='" + "p" + i + "s" + j + "'>0</td>";
    stats ["p" + i + "s" + j] = 0;
    }
    tableHTML += "</tr>";
    }
    var pbutton = null;
    var sbutton = null;
    var check = function () {
    if (pbutton != null && sbutton != null) {
    stats ["p" + pbutton + "s" + sbutton] = stats ["p" + pbutton + "s" + sbutton] + 1;
    document.getElementById ("p" + pbutton + "s" + sbutton).innerHTML = stats ["p" + pbutton + "s" + sbutton];
    pbutton = null;
    sbutton = null;
    }
    }
    window.onload = function () {
    document.getElementById ("stats").innerHTML = tableHTML;
    }
    That for the js and add:
    Code:
    <table id="stats">
    </table>
    Where you want the table to be.
    Hope it helps!

  7. #7
    Join Date
    Mar 2006
    Location
    Belgium
    Posts
    81
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I gives an error: "document.getElementById ... is null or not an object"

    how 'bout if i send u the code i've written, so u can see where i want to go to?

  8. #8
    Join Date
    May 2006
    Location
    Alaska
    Posts
    163
    Thanks
    5
    Thanked 2 Times in 2 Posts

    Default

    Sure, my email is: sub.atomic.fusion@gmail.com
    Actually I don't know whats wrong. I never test things in IE anymore and it says "unknown error" in it anyway. It appears to have a problem with my "d" in document, what browser do you use anyway?
    Last edited by ???; 08-11-2007 at 02:12 PM.

Bookmarks

Posting Permissions

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