Topic: Forms in JavaScript Game (Page 1 of 1) Pages that link to <a href="https://ozoneasylum.com/backlink?for=31522" title="Pages that link to Topic: Forms in JavaScript Game (Page 1 of 1)" rel="nofollow" >Topic: Forms in JavaScript Game <span class="small">(Page 1 of 1)</span>\

 
MatrixClaw
Obsessive-Compulsive (I) Inmate

From:
Insane since: Dec 2009

posted posted 12-08-2009 08:02

Hello, this is my first post here, but I'm having some trouble figuring out what I messed up on my code

I'm making a Javascript game of Hangman for one of my classes and I originally had the input as a text box where you physically type in the letter and if it was wrong, it would draw the next sequence of the hangman picture and place the letter in another text box as a "Used Letters," or if you're right, it would place the letter you chose in the box for the word you're guessing. However, I decided that instead of doing that, I wanted to make it more visually appealing and add buttons with the letters on them instead as you can see here: www.mediafire.com/?mijjldzmmjd (the one with the _2 is the one I'm currently using, but the original is supplied as well).

The buttons register the correct letters just fine (you are able to win), but it still doesn't place the used letters in the right boxes (it is replacing them in the letters instead? - If you continue to click the same letter over and over, it will keep replacing the buttons with the same letter until they're all replaced and then it finally starts putting them in the "Used Letters" section, and finally the "word" section).

Any ideas? I'm sure there's some simple thing I'm missing, but I can't for the life of me find it. I'm only used to more simple coding, so troubleshooting on this large of a code is confusing me! haha

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 12-10-2009 01:46

You're using

document.forms[0].elements[letterPosition].value = letter

when a letter is clicked. This only works if the letter boxes are the first elements in the form, so that starting letterPosition at 0 corresponds to the first letter box.

You could fix this by giving the letter boxes names (like "letter0", "letter1", etc), or by putting them in a separate <form> and using document.forms[ 1 ], etc.




(Edited by Slime on 12-10-2009 01:50)

(Edited by Slime on 12-10-2009 01:50)

X7JAY7X
Obsessive-Compulsive (I) Inmate

From:
Insane since: Dec 2009

posted posted 12-10-2009 02:04

Edited. Wrong thread.

(Edited by X7JAY7X on 12-10-2009 02:05)

coach
Nervous Wreck (II) Inmate

From:
Insane since: May 2011

posted posted 05-31-2011 11:03
Edit TP: spam removed


Post Reply
 
Your User Name:
Your Password:
Login Options:
 
Your Text:
Loading...
Options:


« BackwardsOnwards »

Show Forum Drop Down Menu