tailieunhanh - DHTML Utopia Modern Web Design Using JavaScript & DOM- P9
DHTML Utopia Modern Web Design Using JavaScript & DOM- P9:In a single decade, the Web has evolved from a simple method of delivering technical documents to an essential part of daily life, making and breaking relationships and fortunes along the way. “Looking something up on the Internet,” by which is almost always meant the Web, is now within reach of almost anyone living in a first-world country, and the idea of conducting conversations and business (and probably orchestras) in your Web browser is no longer foreign, but part of life | Chapter 6 Forms and Validation File excerpt var errText We re going to step through all the form elements and check only the ones our validation set has regular expressions for File excerpt for var i 0 i i if i .name validationSet i .name Next we see some code that prepares the in-page error message elements it s the same as the code we used in checkValid. Now let s start to display the error message s to the user. File excerpt if failedE errDisplay validationSet error In this first case validation failed and a span for the field does exist so we write the error message in-page as before. File excerpt if IfailedE errDisplay In this second case there s no error but there is a span so we clean up any lingering error text that was previously displayed in-page. Whenever we have an error we also want to collect up the message for display in a single summary. That s what this next piece of code does File excerpt if failedE var labels label errText validationSet error for var j 0 j j if labels j .htmlFor errText - 1 140 Licensed to siowchen@ Checking on Submission field labels j . If you look at this code closely you ll see that we re not only grabbing the message associated with the field we re also adding the content of the field s label to the error message. That will tie what the user sees on the screen with what they see in the error message. Sadly there is no so we are forced to iterate through each label element on the page and compare its htmlFor6 property with the id of the given form element. If we find a match we extract the label s content the nodeValue of the firstChild which is the text node and
đang nạp các trang xem trước