HTML and CSS Reference
In-Depth Information
input. Fix the errors so that the form does not submit if there is no input in the
Name input box. Correct the errors and describe the process you followed.
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en" xml:lang="en">
<head>
<title>JavaScript Practice</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript">
<!-- <![CDATA[
function validateForm()
{
if (document.forms[0].userName.value == "" )
{
aert("Name field cannot be empty.");
return false;
} // end if
aert("Name and age are valid.");
return true;
} // end function validateForm
// ]]> -->
</script>
</head>
<body>
<h1>JavaScript Form Handling</h1>
<form method="post" action="http://webdevfoundations.net/scripts/
formdemo.asp" onsubmit="return validateUser();">
<label>Name: <input type="text" name="userName" /></label>
<br />
<input type="submit" value=“Send information" />
</form>
</body>
</html>
Hands-On Exercises
1. Practice writing event handlers.
a. Write the XHTML tag and event handler to pop up an alert message that says
“Welcome” when the user clicks a button.
b. Write the XHTML tag and event handler to pop up an alert message that says
“Welcome” when the user moves the mouse pointer over a hypertext link that
says “Hover for a welcome message”.
c. Write the XHTML tag and event handler to pop up an alert message that says
“Welcome” when the user moves the mouse pointer away from a hypertext link
that says “Move your mouse pointer here for a welcome message”.
2. Create a Web page that will pop up an alert message welcoming the user to the
Web page. Use a script block in the <head> area for this task.
 
Search WWH ::




Custom Search