HTML and CSS Reference
In-Depth Information
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.
JavaScript function converts
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
Press the
e n t e r key
once to
a blank
line, and
point on
line 19.
converts value
to integer
converts DownPayment
amount and tests if
value is a valid number
alert() function
will display
error message
calculates loan
amount and
sets value in
text field,
sets focus() to
text field
focus set to text
field for user to
re-enter data
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.
Enter the
braces close if and
else statements
Figure 10-19
Press the
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.
Enter the JavaScript code shown in Table 10-13 on the previous page, indenting as shown to
Press the
e n t e r key once after line 44 (Figure 10-19).
Are spaces necessary around equal signs in JavaScript statements?
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.
Search WWH ::

Custom Search