HTML and CSS Reference
In-Depth Information
Overview
As you read this chapter, you will learn how to write embedded JavaScript code
to create the Web pages shown in Figures 10-1a and 10-1b on the previous page by
performing these general tasks:
Open an existing HTML file and add JavaScript code.
Create a scrolling message in a text field.•
Convert the text field values to numeric values using built-in functions.
Validate data entered into a form as numeric and greater than zero.
Calculate a mortgage loan amount based on the selling price minus the down
payment amount.
Calculate a mortgage loan monthly payment based on loan amount, interest rate, and
number of years.
Format the monthly payment to display as currency.
Open a pop-up window when the Web page initially loads.
Display the date the Web page was last modified.
Save, validate, and test the Web pages.
Print the HTML code and Web pages.
Plan
Ahead
General Project Guidelines
When adding JavaScript or any scripting language to a Web page document, the actions
you perform and decisions you make will affect the appearance and characteristics of the
finished Web page. Before you write the JavaScript code, you should follow these general
guidelines:
Determine what you want the code to accomplish.
For this chapter's project, you want
to create a scrolling message in a text field, add a pop-up window, create a form for user
input, validate the user input, perform a calculation based on the user input, output a
result formatted as currency, and display the date the Web page was last modified.
Determine the overall Web page appearance.
When the Web page first loads, a
pop-up window is displayed. The Web page also includes a text message that scrolls
continuously. Data for the mortgage loan calculation is entered in a form, validated,
and the results are displayed in currency format. The copyright and date the page was
last modified display at the bottom of the page.
Determine the data validation requirements.
Before the monthly payment can be
calculated, the data entered in the form must be validated. The selling price, down
payment amount, interest rate, and the number of years for the loan must be numeric,
not blank, and greater than zero. If the data does not meet these criteria, an alert
message box notifies the user and positions the insertion point in the appropriate text
field. When validating the down payment amount, it should not be greater than the
selling price.
Determine the calculations needed.
You will need a formula for calculating the
loan amount, based on a sales amount minus the down payment, and the monthly
payment. The formulas are given later in the chapter.
When necessary, more specific details concerning the above guidelines are presented at
appropriate points in the chapter. The chapter will also identify the actions performed and
decisions made regarding these guidelines during the creation of the Web page shown in
Figure 10-1.
 
Search WWH ::




Custom Search