Web Programming ct214H Lab2 Css Js
Web Programming ct214H Lab2 Css Js
v Requirement:
- Do the examples in the lecture, browse them, and obverse the results.
- Make some changes to the examples and observe the results.
v Hints:
- Use the <div> tag to group the elements.
- The page contains 1 outer box (dark red border) with 1 heading, 1 image, and
1 inner box for displaying the text.
Web Programming Fundamentals Labs (CT214H) – TS. Trần Công Án -9-
- Suggested steps:
1) Create the boxes and insert the content into these boxes. Ignore the
format in this step. Result of this step: http://bit.ly/OGxFOk
2) Format the boxes:
o Outer box: width 400px, background color LightYellow, border
attribute 3px solid brown. You can add paddings between the content
and the border.
o Image border: style inset, width 5px, and Orange color.
o Inner box (containing text): set the size, border, and background as
described in the requirement. Note: use the overflow attribute
appropriately to avoid the content flowing out of the box.
o Inner box (containing text): set the size, border, and background color
as described. Note: use the overflow attribute to set the text wrap and
display the scrollbar.
o Add a border and background for the Useful Links and make it float
to the right, as shown in Figure 12.
o Background image for the content box: http://bit.ly/1mMNNsR
v Requirements:
1) Design a webpage as shown in Figure 13.1
2) When the user clicks on the button “Giải phương trình”, a JS code will be
called to calculate the delta and solution x1 and x2.
3) The computed values will be displayed on the page as in Figure 13.2
4) Advanced: Check the form elements’ value before solving the equation and
show the appropriate messages if the input values are invalid (see Figure
13.3).
v Hints:
1) The webpage has 1 form, which contains 3 textfields and 1 button. To show
delta, x1, and x2 values, we insert empty <span> tags. We must set the id
property for these spans so that we can access these spans later using this
property. Between the span to display delta and x1, we insert a <p> tag to
Web Programming Fundamentals Labs (CT214H) – TS. Trần Công Án -17-
display the message about the number of solutions. This <p> tag is also
assigned an id.
2) Write a JS function to solve the quadratic function and call this function in
the onclick event of the “Giải phương trình” button. The JS function accesses
the form elements to get the value of a, b, and c variables using the
document.getElementById() function. It also uses DOM to set the delta value,
message on the number of solutions, and x1 and x2 values.
3) Write code to check and validate the input values. To display the message
when the input value is invalid, insert a <p> tag next to each textfield. You
can also make a further improvement so that the element containing invalid
input will be focused (by calling the focus() method of the element).
v Requirement:
1) Create a form as shown in Figure 14.
2) When the Clear button is clicked: clear the content of all elements.
3) When the Finish button is clicked: validate the form element as follows:
o All mandatory fields must be non-empty.
o Email: must contain one “@”, before “@” is an account name, after “@” is
a domain name, the domain name has at least one “.”
o DOB: should be in mm/dd/yyyy format.
o Zip code: includes exactly 5 digits.
v Requirement:
1) Open the VC page in Lab 1 and remove all formats (except the table size).
2) Use CSS to format the webpage to make it similar to Figure 15.
v Hint:
1) Text color and font: select the page body and use the color property to set the
text color (#454545) and font-family property to set the font face (Georgia).
2) The top header: set the font-variant property value to small caps. Other
formats for this header: observe and do it by yourself.
3) The 2nd level header: set all of them to the same class and the following
properties for this class: text-align (left), color (black), padding-top, padding-
bottom, font-size, font-weight, and border-top.
4) The right column: use the text-align property to specify the horizontal
alignment and the vertical-align property to specify the vertical alignment.
5) Space between 2 columns: in Lab 1, we used the cellpadding property to
specify the space between 2 columns. However, this property affects all 4
sides of a cell. So, increasing the space between two columns also increases
the space between rows. CSS allows us to adjust the space on each side of a
cell separately, and thus we will use it to increase the space between 2
columns while still keeping the space between the rows unchanged. To
increase the space between the table columns, we increase the right padding
for the cells in the 1st column. The key problem is to create a selector that can
select all the cells of the 1st column so that we can set their padding-right
property. Alternatively, we can assign these cells to a class and select this
class to apply the format. The first solution is better than the second one.
• Alignment: center.
• Border: 4px width, gray color, solid style, corners rounded 20px.
5) Format of the General Overview section (on the right):
Note: You can only add properties such as id, class, etc., for the element in the
file “film-review.html”. Other modifications are not allowed. All CSS formats must
be placed in the CSS file.
<body>
#banner
#title
#content
#rating_review
#rating
#review
.review_box
.reviewer
#general overview
#overview_text
#total
title
rating
rating_
review
review
_box
reviewer
general
overview
content
overview
_text
review
total
Figure 17. Page structure
The results after each step are given in the following links:
0) http://bit.ly/1pO9hbh (initial/unformatted page)
1) http://bit.ly/1fQW1hK
2) http://bit.ly/1bV2gl3
3) http://bit.ly/1htRVwA
4) http://bit.ly/1lsnPwH
5) http://bit.ly/1hRzPmv
6) http://bit.ly/1fSAbu8
7) Figure 16 (final result)
v Requirement:
1) Design a simple calculator, as shown in Figure 18.
2) The user can use the keyboard or click on the buttons of the calculator to
input an expression which includes 2 operands and 1 operator (+, -, *, /)
3) Validate the user input. If the expression is valid, evaluate the expression and
show the result. Otherwise, show an appropriate message.
v Hint:
1) UI design: 1 textfield and 16 buttons. User font Courier New for the text on
the button.
2) Hanle the mouse click event of the buttons:
• Numbers and operators: append to button label to the textfield value
• Equal (=) button: calculate the expression in the textfield (use the eval()
function or write your own code to evaluate the expression) and display
the result. To ensure the inputted expression is valid, we can use the
regular expression to validate it.
v Hints:
1) Create 3 CSS files for 3 different themes: default, dark and colorful theme.
2) By default, we use the default theme by importing the default CSS file into the
webpage using the following tag:
<link href="default.css" type="text/css" rel="stylesheet" id="themeCSS"/>
We assign an id for this tag so that we can select it and change the CSS file
later.
3) Write a JS function that gets a theme name and changes the href property of
the <link> tag to the corresponding CSS file:
document.getElementById(“themeCSS”).href = <path to the CSS file>;
4) In the onchange event of the dropdown list (<select>), call the JS function to
change the theme of the calculator based on the value selected in the
dropdown list.