Help - Search - Members - Calendar
Full Version: Function not carried out?
HTMLHelp Forums > Programming > Client-side Scripting
jlittle15
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
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. happy.gif

HTML
<form name="Transportaion">
pandy
Also, turn on your browser's error console. It will give you useful, but sometimes cryptic, hints.
Christian J
Also, document.write will overwrite the existing web page. If that's not what you want, change the innerHTML of some HTML element instead.
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2019 Invision Power Services, Inc.