SitePoint Sponsor |
|
User Tag List
Results 1 to 3 of 3
Thread: Simple JavaScript Game
-
May 22, 2007, 13:23 #1
- 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.
-
May 22, 2007, 14:58 #2
- 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'); } } }
-
May 23, 2007, 06:08 #3
- 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