Xem mẫu

This example creates a button that runs a function called verifydata when it`s clicked. You provide the label that appears on the button with the value attribute of Verify Data. Unlike Submit buttons, regular buttons don`t submit the form when they`re clicked. Hidden Form Fields Hidden form fields are used when you want to embed data in a page that shouldn`t be seen or modified by the user. The name and value pair associated with a hidden form field will be submitted along with the rest of the contents of the form when the form is submitted. To create such a field, set the field`s type to hidden and be sure to include both the name and value attributes in your tag. Here`s an example: Hidden form fields are generally used when data identifying the user needs to be included in a form. For example, let`s say you`ve created a form that allows a user to edit the name and address associated with her bank account. Because the user can change her name and address, the data she submits can`t be used to look up her account after she submits the form, plus there might be multiple accounts associated with one name and address. You can include the account number as a hidden field on the form so that the program on the server knows which account to update when the form is submitted. The File Upload Control The file control enables a user to upload a file when he submits the form. As you can see in the following code, the type for the input element is set to file: Input

Please select a file for upload:

Figure 10.10 shows a file upload control. Output file:///G|/1/0672328860/ch10lev1sec3.html (8 von 9) [19.12.2006 13:49:17] Figure 10.10. The file upload control. If you want to use a file upload field on your form, you have to do a lot of behind-the-scenes work to get everything working. For one thing, the program specified in the action attribute of your form must be able to accept the file being uploaded. Second, you have to use the post method for the form. Third, you must set the enctype attribute of the
tag to multipart/form-data. I haven`t discussed the enctype attribute because this is the only case where you`ll have to use it. Ordinarily, the default behavior is fine, but you must change the enctype in this particular case. Let`s look at a simple form that supports file uploads:
After you`ve created a form for uploading a file, you need a program that can process the file submission. Creating such a program is beyond the scope of this book, but all popular web programming environments support file uploads. file:///G|/1/0672328860/ch10lev1sec3.html (9 von 9) [19.12.2006 13:49:17] Using Other Form Controls In addition to form controls you can create using the input element, there are three that are elements in and of themselves. Using the button Element A button you create using the button element is similar to the buttons you create with the input element, except that content included between the opening and closing button tags appears on the button. Note The button element (as opposed to the input element of type="button") is not supported by versions of Netscape prior to version 6. You can create three different types of buttons: Submit, Reset, and Custom. The The button element is shown in a browser in Figure 10.11. Output Figure 10.11. The button element provides a more flexible way to create form buttons. file:///G|/1/0672328860/ch10lev1sec4.html (1 von 9) [19.12.2006 13:49:18] With the