Download append.html
to your own lab3
folder, i.e., csis390/labs/lab3
append.html
in Chrome. Note that it has a label and input text field.
append.html
in Notepad++ and notice how the label and input text field are created using JavaScript.
div
, label
and input
field for entering Birthday and then append it into the form.type="date"
for the input element.
"pony_birthday"
as the name
and id
of the input element.
div
elements a 1px solid gray border
, add border-radius
, padding
and margin
.
Make the label
elements display
block. Give the input
elements a height
of 1.6rem
and a font-size
of 1.1rem.
append.html
as event.html
event.html
in you web browser.input
element
where type="submit"
value="Insert"
for the submit button
"action_button"
as the name
and id
for the submit button.
script
tag):ponyForm.addEventListener("submit", checkForm);
script
tag):function checkForm(event) { alert("Submitting form"); }
event.html
and re-open/refresh it in Chrome.
input[type~="submit"]
and give it a height of 2.5rem and a lightgreen background-color. Add padding, border, border-radius,
and box-shadow to approximate the image above.
this
refers to the submit button. In general, this
can
be used to refer to the object that is the "subject" of the event. Rather than define separate functions
for changing the submit button, we use an anonymous function because the function won't be reused.
To learn more about the code you just added, read about:
Verify that event.html
validates at:
html5.validator.nu
Show your instructor that the hover effect works, that the alert pops up and that the form submits properly.
event.html
as valid.html
valid.html
in you web browser.checkForm
function to make sure the Name is not blank,
and to make sure the birthday year is valid. For testing purposes, a valid birthday year
should be between 2000 and 2015.
checkForm
function
var ponyNameElement = document.querySelector("#pony_name");
var submittedName = ponyNameElement.value;
if (submittedName == "") { // The name is blank }
event.preventDefault();
ponyNameElement.style.border = '5px solid red';
ponyNameElement.parentNode.style.color = 'red';
div
.
label
by using parent-child relationships and change the innerHTML to be the
error message.ponyNameElement.parentNode.firstChild.innerHTML = "Name is required"
label
tag inside the pony name's div
.
if-else
statement to switch the style back if the value is valid:
if (submittedName == "") { ponyNameElement.style.border = '5px solid red'; } else { ponyNameElement.style.border = "1px solid gray"; }
var birthdayString = ponyBirthdayElement.value;
var birthdayArray = birthdayString.split("-");
if (birthdayArray[0] < 2000)
Verify that valid.html
validates at:
html5.validator.nu
Then, try submitting your form with invalid and valid values. Make sure it works.
Create a zip file of your lab3
folder called lab3.zip
and submit the file in Blackboard. The zip file should contain three files:
append.html
, event.html
and valid.html
.
In the comment area of Blackboard put your partner's name.
The deliverable must be submitted in Blackboard by midnight on the day before your next scheduled lab meeting. If you wish to work alone, you can submit the deliverable yourself. However, you are encouraged to work with your partner and you can submit together. When submitting as a lab pair, be sure to include your partner's name in the comment area when you submit via Blackboard.
Outside of lab, you are only permitted to work with your lab partner. Do not share your work with any other student.