Tự học HTML và CSS trong 1 giờ - part 47

Tham khảo tài liệu 'tự học html và css trong 1 giờ - part 47', công nghệ thông tin, đồ họa - thiết kế - flash phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả | 436 LESSON 15 Using JavaScript in Your Pages Validating Forms with JavaScript Remember the example form that you created back in Lesson 11 Designing Forms It s shown again in Figure . It s a typical registration form for a website with several required fields. FIGURE The registration form. What happens when this form is submitted In the real world a script on the server side validates the data that the visitor entered stores it in a database or file and then thanks the visitor for her time. But what happens if a visitor doesn t fill out the form correctly for example she doesn t enter her name or choose a value for gender The script can check all that information and return an error. But because all this checking has to be done on the server and because the data and the error messages have to be transmitted back and forth over the network this process can be slow and takes up valuable resources. JavaScript enables you to do error checking on the browser side before the form is ever submitted to the server. This saves time for both you and your visitors because everything is corrected on the visitors side. After the data actually gets to your script it s more likely to be correct. Download from Validating Forms with JavaScript 437 Task Exercise Form Validation Now take a look at how the registration form is validated with JavaScript. Whenever you click the Submit button on a form two events are triggered the onclick event for the button and the onsubmit button for the form. For form validation onsubmit is the better 15 choice because some forms can be submitted without clicking the Submit button. When the onsubmit event is fired the validation function will be called. The onsubmit attribute is set in the form tag like this form method post action http register onsubmit return checkform this In this example the value assigned to onsubmit is a call to a function named checkform which is defined in the page header. But .

Không thể tạo bản xem trước, hãy bấm tải xuống
TÀI LIỆU MỚI ĐĂNG
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.