Presentation is loading. Please wait.

Presentation is loading. Please wait.

5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML.

Similar presentations


Presentation on theme: "5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML."— Presentation transcript:

1 5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML

2 What can we do with DHTML

3 What can we do with DHTML?

4 Event-Driven Programming and DOM Events Event handlers DOM

5 DHTML - What techniques do we need? Find the HTML object we want to change var domLink = document.getElementById("linkToAnimal"); Change the object’s: –HTML properties domLink.href = "cat.html"; –CSS properties domLink.style.backgroundColor = "blue"; Register event handler domButton.addEventListener(“click”, changeLink)

6 Cash Register Example Total money: $0.00 $0.05 $0.10 $0.25

7 Exercise #1 – Change this code to make the element have a large font when you move the mouse over it. Bigger Welcome to my page!

8 Form Validation Example <form method=“post" onsubmit="return confirmSubmit()" action="http://www.usna.edu/Users/cs/adina/teaching/sy306/tools/FormChecker/submit.cgi" > Last name: Number attending(1-100): <input type="text" name="numAttend" id="numAttend" onblur="return checkAttending()" />

9 //check if last name is filled out function checkLastName(){ var lastNameDOM = document.getElementById("lastName"); var lastNameError = document.getElementById("lastNameError"); var lastName = lastNameDOM.value; //something in the last name field if (lastName){ lastNameError.innerHTML = ""; return true; } //nothing in the last name field else{ lastNameError.style.color = "red"; lastNameError.innerHTML = "*Please fill in the last name"; return false; } // Returns true if the number of attending is okay function checkAttending() { var numDOM = document.getElementById("numAttend"); var numAttendError = document.getElementById("numAttendError"); var numAttend = numDOM.value; if ( (numAttend >= 1) && (numAttend <= 100) ){ numAttendError.innerHTML = ""; return true; } else { numAttendError.style.color = "red"; numAttendError.innerHTML = "*Attendance: Please enter a value between 1 and 100."; return false; }

10 // Asks user to confirm submission, returns true if ok function confirmSubmit() { if (!checkAttending() || !checkLastName()) return false; if (window.confirm("Are you sure you want to submit?")) return true; else return false; }

11 All Kinds of Events onblur onfocus onchange onclick ondblclick onload ( only) onmousedown, onmouseup, onmouseout, onmouseover, onmousemove onselect (, only) onsubmit ( only) onunload ( only)

12 Exercise #2 – Modify so that clicking on the button changes target of element to “dog.html” Change Link See some animals!

13 Exercise #3 – Write a form to read in a password from the user in two boxes. When they submit the form, proceed only if the passwords are the same.


Download ppt "5 th and 4 th ed: some from chapters 9, 12, 13 SY306 Web and Databases for Cyber Operations Slide Set #8: Dynamic HTML."

Similar presentations


Ads by Google