div>
form>
ody>
html
Discussion
(1) link to desktop CSS file
Answer:
(2) link to JavaScript data validation file
Answer: script
(3) add a form identifier, so we can easily reference the form object
Answer: id="regform"
Step 6: CSS Creation (for the form)
6.1 Open file desktop.css, review the CSS and the questions below.
For your convenience, the code is shown below:
COS10005 – Web Development XXXXXXXXXXLast Updated: 12th October 2020 Page 4
Discussion
(4) What happens if “border:none” is removed from the fieldset declaration?
COS10005 – Web Development XXXXXXXXXXLast Updated: 12th October 2020 Page 5
Answer: The input for gender will be enclosed in a fieldset box, the word "Gender" – the
legend - will be in the box, not in its default position along the top left of the box.
(5) Why is there a blank space and not a comma between these selectors? However, in
a previous lab we used a comma, for example
h1, h2, p {
color : blue;
}
Answer: A blank space represents a contextual selector. This means that the style is to be
applied only to HTML elements that are descendants of the class "radioinput".
Note that when the border was set to none (as was asked in question 6) the
fieldset for Account and User Information still retains its border.
"Comma" represents a grouping selector.
This means that the style rule is to be applied to all to these HTML elements. In
the above grouping example, the color:blue will be applied to all h1, all h2 and
all p, unless it is ove
idden by another later CSS declaration.
Step 7: JavaScript Creation (for the form data validation)
7.1 Open the text file validation.js, review the JavaScript and the questions below. For your convenience,
the basic code and additional code is shown below:
COS10005 – Web Development XXXXXXXXXXLast Updated: 12th October 2020 Page 6
COS10005 – Web Development XXXXXXXXXXLast Updated: 12th October 2020 Page 7
(6) The property value has been used to access the text input, in the previous four line of code.
What property needs to be used to access the radio input values?
Answer: The property is checked, thus to obtain the value stored in a radio input, the following
JavaScript code needs to be added:
var genm = document.getElementById("genm").checked;
var genf = document.getElementById("genf").checked;
(7) How would you check if each input field is empty?
Answer: Add the following JavaScript Code:
XXXXXXXXXXif (sid == "") {
e
Msg += "User ID cannot be empty.\n"; \n will create a ‘new line’ code in the message,
that
} will be displayed in the
if (pwd1 == "") { alert
e
Msg += "Password cannot be empty.\n";
}
if (pwd2 == "") {
e
Msg += "Retype password cannot be empty.\n";
}
if (uname == "") { e
Msg += "User name
cannot be empty.\n";
}
if ((genm == "")&&(genf == "")) {
e
Msg += "A gender must be selected.\n";
}
Note: You need to test all options in a radio input. In this case, both genm and genf must be tested.
(8) How would you check if an input field contains an @ symbol?
Answer: Add the following JavaScript code:
XXXXXXXXXXif (sid.indexOf('@') == 0 ) { e
Msg += "User ID
cannot start with an @ symbol.\n";
}
if (sid.indexOf('@') < 0 ) { e
Msg += "User ID
must contain an @ symbol.\n";
}
Note: This is simplistic way to check if the input is an email address. A better solution would be to use a
egular expression.
An example of a regular expression is included in this lab, to check if the name input
field only contains only letters and/or spaces. See the