SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Simple JavaScript Game

    Could any one point me in the right direction to where I can find information on building a simple JavaScript game?
    I just need JavaScript to validate a form, and tell the person if h/she has answered the question correctly. For example; If the question was, what color is the sun? And h/she answered blue, then pressed the submit button. A text box would pop up explaining that h/she has answered incorectly. If h/she answeres yellow. Then on submit would send that person to the next page.

    Thank you.

  2. #2
    I meant that to happen silver trophybronze trophy Raffles's Avatar
    Join Date
    Sep 2005
    Location
    Tanzania
    Posts
    4,662
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    I would expect it can be as simple as this:
    HTML Code:
    <form action="questions.php?q=2" method="post">
      <p>
        <label for="q">What colour was Napoleon's white horse?</label>
        <input id="q" type="text" name="ans" rel="white">
      </p>
      <p><button id="submitter">Submit answer</button></p>
    </form>
    Code javascript:
    window.onload= function() {
      document.getElementById('submitter').onclick = function() {
        var q = document.getElementById('q');
        if (q.value == q.rel) {
          this.parentNode.parentNode.submit();
        }
        else {
          alert('Wrong answer');
        }
      }
    }
    That's a very simple way that makes cheating easy as long as people know to look in the source code (I'm assuming this is a trivial game). Once the form is submitted, you can use the answer on the next page if you need, since it will have been sent by POST.

  3. #3
    SitePoint Enthusiast
    Join Date
    Apr 2006
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you Raffles, that is exactly what I'm looking for.


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
  •