Escolar Documentos
Profissional Documentos
Cultura Documentos
HTML Forms,
The Forms Object
1
The Document Object Model
• The DOM (Document Object Model) defines
1. how to navigate and manipulate the HTML structure
2. a set of objects related to HTML
2
DOM as a Tree
(The HTML document) (The DOM as a tree)
<html> <html>
<head>
<title> My Page </title>
</head> <head> <body>
<body>
<h1> Level 1 </h1>
<h2> Level 2 </h2> <title> <h1> <h2>
<h3>
<h3> Level 3 </h3>
</body>
</html>
“My Page” “Level1” “Leve2”
‘Leve3”
• What is the child nodes of the <html> node?
3
Browser Object Model (BOM)
Current window
4
The JavaScript Hierarchy
Current window
<script language="JavaScript">
// display all the properties of the document
object
</script> 6
Properties of the document object
<head>
<title>Document Object Properties</title>
</head>
<body bgColor="silver" text="forestgreen" link="blue"
vlink="purple">
<font face="arial" size="+2">
<script language="JavaScript">
var beg="<em>", end="</em><br>";
document.write("Location: " + beg + “ “ + end);
document.write("Title: " + beg + “ “ + end);
document.write("Background color: " + beg + “ “ + end);
document.write("Link color: " + beg + “ “ + end);
document.write("Vlink color: " + beg + “ “ + end);
document.write("Text color: " + beg + “ “ + end);
document.write("Last modified: " + beg + “ “ + end);
</script>
</body>
• Use the location, title, bgColor, linkColor, vllinkColor, fgColor, 7
lastModified properties of the document object
Properties of the document object
8
HTML Forms
Server
User input
The user input will be
Processed by
a server side program:
CGI, ASP, PHP
9
HTML Forms
<form action="https://post.uww.edu/exchweb/bin/auth/owaauth.dll"
method="post">
10
HTML Forms
<form action=“URL to server program" method=“post“>
The body of the form goes here including input devices such as
radio buttons, menu, text boxes,..
</form>
11
HTML Forms
12
HTML Forms
<form>
<p>Type your name:
<input type = "text" name ="namestring" size = "50"></p>
<p>
Choose a work place:
<input type = "checkbox" name="place" value="SJ"> San Joise
<input type = "checkbox" name="place" value = "SF"> San Francisco
</p>
<p>
<input type="submit" value = "Submit">
13
<input type="reset" value = "Clear"></p>
</form>
The forms object
• What can JavaScript do for the HTML form?
Before sending the form off to the server,
JavaScript can be used to validate the data that was
entered into the form by using the event handlers.
14
The forms object
• JavaScript provides objects that parallel HTML tags;
JavaScript HTML
15
The forms[] Array
• HTML • JavaScript
<html>
<form> window
….
</form>
<form>
document
….
</form>
<form>
… forms[0] forms[1] forms[2]
</form>
</html>
17
The elements[] Array
<html>
<form name="form1">
<input type="text"
name="yourname"><br>
<input type="button" name="button1"
value="Push Button">
</form>
18
The elements[] Array
<html>
<form name="form1"> window
<input type="text"
name="yourname"><br
>
document
<input type="button"
name="button1"
value="Push Button">
</form> forms[0] forms[1]
“form1” “form2”
<form name= "form2">
<input type = "radio"
name="veggie1"
value="bean">Beans
<input type = "radio" elements[0] elements[1] elements[0] elements[1]
name="veggie2" “yourname” “button1” “veggie1” “veggie2”
value="carrot">Carrots
</form>
</html> 19
The elements[] Array
<html>
• How do we refer to the button1 ?
<form name="form1">
<input type="text" document.forms[0].element[1]
name="yourname"><br
> ducment.form1.button1
<input type="button"
name="button1"
value="Push Button">
</form>
… ….
21
Properties of the element object
• The element object in JavaScript has properties that correspond to
the HTML attributes of the form elements (input devices).
<input type=“…” name=“…” value=“…”>
22
Naming Forms and Buttons
<form name="form1">
Enter your name: <input type="text"
name="namefield" value="name:">
</form>
<form name="form2">
<input type="button" value="Press
here">
</form>
<script language="JavaScript">
</script>
23
Naming Forms and Buttons
<form name="form1">
Enter your name: <input type="text"
name="namefield"
value="name:">
</form>
<form name="form2">
<input type="button" value="Press
here">
</form>
<script language="JavaScript">
</script>
• Use the name property of the form object.
24
Naming Forms and Buttons
<form name="form1">
Enter your name: <input type="text"
name="namefield"
value="name:">
</form>
<form name="form2">
<input type="button" value="Press
here">
</form>
<script language="JavaScript">
</script>
• Use the name and value properties of the element object.
• Name the file lab10.html and turn in (Due: 4/10, 11:59PM)
25