Function not carried out?, Html - basic madlib |
Function not carried out?, Html - basic madlib |
jlittle15 |
Jan 17 2017, 09:24 PM
Post
#1
|
Group: Members Posts: 2 Joined: 17-January 17 Member No.: 26,269 |
Can't seem to get this coding correct. The function never is carried out when the button its pressed. Any help will be appreciated.
<!DOCTYPE html> <html> <head> <script> function MadLib(){ var a1 = document.AgentID.elements[0].value; var a2 = document.City.elements[0].value; var a3 = document.Country.elements[0].value; var a4 = document.Utensil.elements[0].value; var a5 = document.Adj1.elements[0].value; var a6 = document.Animal.elements[0].value; var a7 = document.Transportation.elements[0].value; document.write("Agent"+a1+","); document.write("<br>"+"<br>"); document.write("Congradulations on accepting your next assignment Agent "+a1+""); document.write("<br>"+"<br>") document.write("Your flight leaves to "+a2+" , "+a3+" in the next eight hours. You have been granted your weapon of choice, the "+a5+" "+a4+". Your assignment is to capture the "+a6+" with minimal casualties. Your extraction via "+a7+" will be waiting."); document.write("<br>"+"<br>"); document.write("Best of Luck Agent "+a1+"",); document.write("<br>"); document.write("Operations HQ"); } </script> </head> <body> <form name="AgentID"> AgentID <input type="text"> </form> <form name="City"> City <input type="text"> </form> <form name="Country"> Country <input type="text"> </form> <form name="Utensil"> Noun <input type="text"> </form> <form name="Adj1"> Adjective <input type="text"> </form> <form name="Animal"> Animal <input type="text"> </form> <form name="Transportaion"> Transportation <input type="text"> </form> <input type="button" value="Accept Your Mission" onClick="MadLib()"> </body> </html> |
pandy |
Jan 18 2017, 05:36 AM
Post
#2
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
You have one error in the JS. You have a comma outside the quotes here.
CODE document.write("Best of Luck Agent "+a1+"",); ^ Not an error, but the quotes at the end here are empty. I guess you meant to have something there. CODE document.write("Congradulations on accepting your next assignment Agent "+a1+""); ^^ It still won't run, because you also have a typo on the HTML. "Transportation" will work better. HTML <form name="Transportaion"> |
pandy |
Jan 18 2017, 05:39 AM
Post
#3
|
🌟Computer says no🌟 Group: WDG Moderators Posts: 20,731 Joined: 9-August 06 Member No.: 6 |
Also, turn on your browser's error console. It will give you useful, but sometimes cryptic, hints.
|
Christian J |
Jan 18 2017, 08:04 AM
Post
#4
|
. Group: WDG Moderators Posts: 9,658 Joined: 10-August 06 Member No.: 7 |
Also, document.write will overwrite the existing web page. If that's not what you want, change the innerHTML of some HTML element instead.
|
Lo-Fi Version | Time is now: 26th April 2024 - 02:24 PM |