Question:

How to make a js point scoring system using onClick

by  |  earlier

0 LIKES UnLike

I need a script that when you click on an image, the document will keep a score, like add 1 for each image clicked.

Need help fast!

 Tags:

   Report

2 ANSWERS


  1. You can just set up a variable in javascript, for example:

    <script type="text/javascript">

    var counter = 0;

    </script>

    and then in your image just add an onclick event like:

    <img src="whatever.jpg" onclick="counter++;" />


  2. I wonder why I get this bored in the mornings?  :D

    Okay I looked at your problem.  JavaScript is the bomb :)

    The one I wrote for you has no storage other than the dom_id that displays the score, also it includes a little bit of styling.  :)  you could make each one different colors for the team ie: Dallas Cowboys vs. Oakland Raiders.  or whatever :)

    This program is very sweet and simple.

    =====[ code start ]======

    <html>

    <head>

    <title>cowboyCoder's score keeper</title>

    <script type="text/javascript">

    function point(element) {

    element.innerHTML = parseInt(element.innerHTML) + 1;

    }

    </script>

    <style>

    .score {

      padding: 20px; font-size: 24px; font-weight: bold;

      background-color: green; color: white;

    }

    </style>

    </head>

    <body>

    click on a team's score to increase it.

    <br/><br/>

    Team 1: <span id="team_1" class="score" onclick="point(this);" >0</span>

    <br/><br/><br/><br/>

    Team 2: <span id="team_2" class="score" onclick="point(this);" >0</span>

    <br/><br/>

    </body>

    </html>

Question Stats

Latest activity: earlier.
This question has 2 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions