文档介绍:Web开发基础HTML form &JavaScript
赵刚
More about HTML-Form
every time you want to collect information from a visitor to your site, you need to use a form
essential of web development
2
Creating a Form with the <form> Element
The <form> element can also contain other markup, such as paragraphs, headings…
A <form> element must not, however, contain another <form> element
your page may contain as many forms as you like---but users will be able to send the data from only one form at a time to the server
essential of web development
3
<form>
Between the opening <form> and closing
</form> tags
the text input boxes
drop-down boxes
checkboxes
submit button
……
essential of web development
4
Ex.
<form action=”” method=”get”>
<h3>Search the site</h3>
<input type=”text” name=”txtSearchItem”/>
<input type=”submit” value=”Search”/>
</form>
essential of web development
5
The form Attribute
The action Attribute
The action attribute indicates what happens to the data when the form is submitted
<form action=”bership/”>
The method Attribute
The get method, which sends data as part of the URL
The post method, which hides data in the HTTP headers
essential of web development
6
Other useful Attribute
The id Attribute
The id attribute allows you to unique identify the <form> element within a page, just as you can use it to uniquely identify any element on a page.
The onsubmit Attribute
onsubmit=”validateFormDetails();”
The onreset Attribute
…
essential of web development
7
Why checks form before sent to the server?
❑ The user does not have to wait the extra time it would take for the page to be sent to the server and then returned if there are any errors.
❑ The server does not have to deal with as much error checking
essential of web development
8
Form Controls
❑ Text input controls
❑ Buttons
❑ Checkboxes and radio buttons
❑ Select boxes (sometimes referred to as drop-down menus) and list boxes
…
essential of web development
9
Text In