HTML and CSS Reference
Line 37 closes the if statement. Line 38 starts the else statement block, which processes the
valid data. Line 39 calculates the loan amount by subtracting the down payment value from
the sales amount. Line 40 assigns the loan amount to the LoanAmount input text field to
display on the form. Line 41 sets the focus to the interest rate input text field to continue
processing the form.
To Add the validSalesAmt() Function with Nested if...else Statements
to Validate Form Data
The following step enters the validSalesAmt() user-defined function and the if...else statements that validate
the amounts entered in the SaleAmount and DownPayment text fields and calculates the loan amount.
Notepad++ button on
the taskbar to display
.html in the Notepad++
If necessary, click the
Click line 18.
value from text field to
integer, tests if value is
a number and greater
than zero; if not, an error
message is displayed and
insertion point placed back
in text field
e n t e r key
amount and tests if
value is a valid number
sets value in
sets focus() to
focus set to text
field for user to
shown in Table 10-12
on page HTML 472,
indenting as shown
to enter the code to
define the variables
for the user-defined functions.
braces close if and
e n t e r key twice after line 22.
enter the code for the user-defined function validSalesAmt(), which validates the data entered
and calculates the loan amount based on the sales amount minus the down payment value.
e n t e r key once after line 44 (Figure 10-19).
No, spaces are not required. You can write one line of code with spaces around the equal signs
and another without spaces and it will not make any difference.