JavaScript Form Letter
Form Letter Assignment: You will change the code examples below so your javascript program will ask the user for 5 variables. One of your variables will be a number. After you click on the button, your program will use these 5 variables in a form letter. In addition, you will add or subtract (or any calculation) something from your number input and use this new variable in the letter, giving you a total of 6 variables. You will print out a listing of your program as well as a copy of 2 different runs of your program, and submit the papers to me after class on April 12. You should try to do this assignment before class on April 8 to see what you need help with during class. See me right away if you have questions. Remember to save different versions of your work and return to a running copy if things get broken. Good luck!
Form Letter with a calculated variable:
You can view the source from the above link, or the code is below. You can try to copy and paste this program into notepad, Save it as fletter.html (or any other name you like with a .html extension) and running the program. Try to make changes, but ALWAYS have a working program you can go back to. A
<html>
<head>
<title> Greetings </title>
</head>
<body>
<h2>Greetings</h2>
<p>
Enter your name: <input type=”text” id=”nameBox” size=12 value=””>
Enter your age: <input type=”text” id=”ageid” size=12 value=””>
</p>
<input type=”button” value=”Click for Greeting”
onclick=”name = document.getElementById(‘nameBox’).value;
age = document.getElementById(‘ageid’).value;
nextyear = parseFloat(age) + 1;
document.getElementById(‘outputDiv’).innerHTML=
‘Hello ‘ + name +
‘, welcome to my page.<br>Do you mind if I call you ‘ +
name + ‘?’+ ‘ I hear you are ‘ +
age + ‘ years old. Next year you will be ‘ + nextyear + ‘ years old.’”>
<hr>
<div id=”outputDiv”></div>
</html>