tailieunhanh - Học JavaScript qua ví dụ part 38

JavaScript và đối tượng hình thức Trong ví dụ trước, các hình thức HTML không có gì để làm với JavaScript. Sau khi mẫu đã được điền đầy đủ, người dùng nhấn một nút Submit và thông tin thường được gửi từ trình duyệt tới một máy chủ trong một định dạng mã hóa URL. Server sau đó sẽ gọi là một ứng dụng trợ giúp máy chủ như PHP hay CGI để xử lý các thông tin. | JavaScript and the form Object 341 Figure An HTML form. JavaScript and the form Object In the previous example the HTML form had nothing to do with JavaScript. After a form has been filled out the user clicks a Submit button and the information is normally sent from the browser to a server in a URL-encoded format. The server then calls a server helper application such as PHP or CGI to handle the information. So where does JavaScript come into all of this Well before sending the form information to the server JavaScript can check to see if the form was filled out properly for example every input field can be validated by JavaScript. It can check for empty fields or improperly filled out fields. For example it can check for the correct format of a credit card number e-mail address zip code and so on. In addition rather than having the user submit the form submission can be controlled by JavaScript with its own submit method. And by naming the forms JavaScript can handle multiple forms and input types respond to user-initiated events and call functions to handle the data that was submitted. From the Library of 342 Chapter 11 Working with Forms and Input Devices As shown in Example a document can have a number of HTML forms and input types called controls such as simple textboxes radio buttons checkboxes and so on. JavaScript provides objects that parallel HTML tags for example the JavaScript form object parallels the HTML form tag and the JavaScript elements object parallels the input devices such as radio buttons or checkboxes. In this section we focus on the structure of the JavaScript form object and how to use it in terms of the Legacy DOM 0 but because DOM 1 is a standardized version some of the examples will include that version. In this chapter you will be introduced to event handling and forms but events will be covered in more depth in Chapter 13. This chapter also includes a section on how to validate input data but in .

TỪ KHÓA LIÊN QUAN