Practical 10 - Javascript Practical Exercise 2: AACS1483 Web Design & Development Practical 10
Practical 10 - Javascript Practical Exercise 2: AACS1483 Web Design & Development Practical 10
Question 1
Design a screen as shown in Figure 1.
Set the New Year date on “January 1, 2021”.
Display current date and the number of days left until New Year in DayCount.htm.
Figure 1
Question 2
The mortgage finance officers at Frontier Savings and Loan have asked you to create a
mortgage calculator that customers can use to estimate monthly mortgage payments. Your
web page should contain a form in which the customer enters the loan amount, the number
of monthly payment, the yearly interest rate, and then clicks a button to see what is the
monthly payment and total payments for the loan. A function named show_Value() is used
to calculate the monthly payment as follows:
Formula applied is
Note that this function uses the Math.pow() method, which calculates the value of a
base value raised to an exponent;
Math.pow(a,n) = an
Once you know the value of the monthly payment, the total amount paid is simply
the monthly payment multiplied by the total number of payments.
Based on the above descriptions and requirements, create the HOME LOAN MORTGAGE
web page using XHTML and JavaScript.
(i) checkform() function to ensure that user has entered the loan
amount, yearly interest rate, number of payment fields. Display an alert message
to user if he/she does not enter any of the required field and set focus back to
the field that is missed out.
(iii) Add an event handler to the calculate button that runs the calculate()
function when this button is clicked.
Figure 2
Question 3
a) Create an external javascript file named “general.js” that contain the following
declaration:
public name;
i. Insert a statement in <head> section to access to the external JavaScript file created
in part (a).
ii. Create a startForm() that will be executed when the form is loaded :
Display the current date into the Order Date field with id “date”.
Prompt user for their name and display in Customer Name field with id
“customerName”.
Set focus in Tel No field with id “telNo”.
Set the default status of the status bar to “CPS Book Shop”
iii. Create a display() function that will be executed when the book selection list (e.g. id
“desc1”) is changed:
Check if the selected index is not equal to 0 (zero),
Then display the book price in the respective text box (e.g. id “price1”), and
Make the respective quantity selection list (e.g. id “quantity1”) to be enabled and
set focus on to the object.
iv. Create a sub() function that will be executed when the quantity selection list (e.g. id
“quantity1”) is changed:
Calculate the Amount of the book purchased by multiplying the book object’s
price and the quantity selected.
Display the Amount in the respective text box (e.g. id “Amount1”)
v. Create a calculate() function that will be executed when the Calculate button is
clicked:
Calculate the Total Amount by adding the values displayed in all the Amount text
boxes.
Display the Total Amount by using dynamic content scripting (object.innerHTML)
into the id “totalAmount”. Display the total amount in the format “RMxxx.xx”.
vi. Create a Submitted() function that will executed when the Submit Order button is
clicked:
Display a confirm dialog box (figure 4) to ask the user “Are you sure to submit the
book order?”
If user clicks on OK button, navigate the page to success.html.
If user clicks on Cancel button, remain to the same page.
vii. Write an onclick event handler for Cancel Order button to display a confirm dialog
box (figure 5) to ask user “Are you sure to cancel order?”. If user clicks on Ok button,
close the window, else reload the form page. Use conditional statement, syntax :
(condition)? True-action: False-action;
Figure 3
Figure 4 Figure 5
Question 4
Chloe MacDonald runs a Web site that contains information on Web page design. She often
finds it necessary to look up the character entity numbers for the Web pages that she
designs. Chloe would like to have this information placed in an easy-to-use table for herself
and for her readers. Rather than entering all 256 character entities into a table, she would
like to use JavaScript to generate the table automatically for her. She’s asked for your help
in writing a JavaScript program to create a 16-by-16 table that display the first 256 character
entities with the entity number and corresponding symbol for each. The design and layout
of the page is up to you. One possible solution is as shown in Figure 6.
Based on the above descriptions and requirements, create the HTML Character Entities web
page JavaScript For Loop structure.
Figure 6
Question 5
Open Q5_txt.html , rename the file Q5.html to and make necessary changes on it.
Figure 8: After the user input, below is the output of the page