HTML and CSS Reference
In-Depth Information
Domain
A domain is a range of
acceptable values for
a field or column in a
database. Using an HTML
select list can ensure
that accurate values
are entered.
Rate text field. The brace in line 52 closes the if statement. If the loanRate data is valid, the
function then proceeds to validate the number of years.
Table 10-15 shows the code used to validate the value selected in the Years drop-
down list.
Table 10-15 Code to Convert and Validate the Years Entered Value
Line
Code
else {
53
loanYears=homeLoanForm.Years.value
54
if (isNaN(loanYears) || (loanYears < 1 || loanYears > 30)) {
55
alert(“Please select a valid number from the list (10, 15, 20,
56
or 30)!”)
57
homeLoanForm.Years.selectedIndex = 0
58
homeLoanForm.Years.focus()
59
}
}
60
}
61
Line 53 is an else statement that executes the statements if the if condition on
line 48 is false. Line 54 receives the selected value from the drop-down menu. The if
statement beginning in line 55 checks the condition to determine if the loanYears value
entered is a number, or is less than one, or is greater than 30. If the number of years is
not valid, line 56 displays a message and line 57 sets the selectedIndex to 0. Line 58 places
the focus back in the Years drop-down menu. The braces in lines 59 through 61 close the
nested if…else statements and the function.
To Enter the CalcLoanAmt() User-Defined Function
The following step enters the CalcLoanAmt() function to validate the Interest Rate (e.g. 4.75) text field and the
Number of Years from the drop-down menu.
1
If necessary,
click
line 45 and then press
the e n t e r key once.
Enter the JavaScript
function to validate
loan rate and
number of years
code shown in
Table 10-14 on the
previous page starting
on line 46 to validate
the interest rate, in-
denting the code as
shown in Figure 10-21.
braces close if,
else, and function
statements
and enter the
JavaScript code shown
in Table 10-15
to validate the number of years for the loan, indenting to align the code as shown in Figure 10-21.
Continue on line 53
Figure 10-21
Press the
e n t e r key to finish the else portions of the nested if...else statements (Figure 10-21).
Why is the year not converted to a floating point number?
Most loans, especially mortgage loans, are NOT made on part of a year, so the number of years should be an integer.
 
Search WWH ::




Custom Search