I am having issues trying to get my javascript code to work. I wanted to use both buttons and input text to play an animation. The buttons work, but I can get the animations to play well with the user's input text. It only plays one specific animation. Any ideas on what can help? I tried using return value to try to get it to look for the user input letter and play the animation based on the letter. Thanks for any help.
function nameTheRock() { //user alert to decide the name for the pet //var namePet=prompt("Please enter your pet name: ", "your name here"); //shows the user the name they choose for thier pet rock //user alert to decide the name for the pet var namePet=prompt("Please enter your pet name: ", "your name here"); //doesn't allow the user not if(namePet != null && namePet!=""){ form.petName.value=namePet; } //checks for errors to ensure user puts in a name else{ alert("Please name your pet"); } } //user key events that allows the user to enter keys j, h, s, b, and g to play animations var userCode = document.getElementById("hiddenText").value; userCode = userCode.toLowerCase(); text = {}; text.command = userCode; function userKey() { //creates variables that containes windows and other browser capability if (userCode ="j") { jumps(); } else if (userCode ="g") { glows(); } else if (userCode ="h") { hops(); } else if (userCode ="b") { blinks(); } else if (userCode ="s") { smiles(); } else { alert("Please use either a button or a letter to play the animation"); } } function jumps() { //When the user click the button it will change the image to an animated gif. This is done by changing the image source to another image that contains the animations. document.getElementById('image').src= "jump.gif"; } function glows() { //When the user click the button it will change the image to an animated gif. document.getElementById('image').src= "glow.gif"; } function hops() { //When the user click the button it will change the image to an animated gif. document.getElementById('image').src= "hop.gif"; } function smiles() { //When the user click the button it will change the image to an animated gif. document.getElementById('image').src= "smiles.gif"; } function blinks() { //When the user click the button it will change the image to an animated gif. document.getElementById('image').src= "blink.gif"; }
Edited by Roger, 19 February 2013 - 04:22 PM.
Added code tags