tailieunhanh - JavaScript Bible, Gold Edition part 199

JavaScript Bible, Gold Edition part 199. This book will bring programmers and non-technical professionals, including casual programmers and scripters, painlessly up to speed on all aspects of mastering JavaScript. Key topics include programming fundamentals, JavaScript language elements and how to use them effectively, and how to easily and efficiently add powerful new functionality to HTML documents and Java applets. | CD-472 Part VI Appendixes Example The following statement assigns a mailto URL to the first form of a page 0 .action mailto jdoe@ elements NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 Compatibility Example The document in Listing 23-2 demonstrates a practical use of the elements property. A form contains four fields and some other elements mixed in between see Figure 23-2 . The first part of the function that acts on these items repeats through all the elements in the form to find out which ones are text box objects and which text box objects are empty. Notice how I use the type property to separate text box objects from the rest even when radio buttons appear amid the fields. If one field has nothing in it I alert the user and use that same index value to place the insertion point at the field with the field s focus method. Listing 23-2 Using the Array HTML HEAD TITLE Elements Array TITLE SCRIPT LANGUAGE JavaScript function verifyIt var form 0 for i 0 i i if i .type text i .value alert Please fill out all fields. i .focus break more tests more statements SCRIPT HEAD Appendix F Examples from Parts III and IV CD-473 BODY FORM Enter your first name INPUT TYPE text NAME firstName P Enter your last name INPUT TYPE text NAME lastName P INPUT TYPE radio NAME gender Male INPUT TYPE radio NAME gender Female P Enter your address INPUT TYPE text NAME address P Enter your city INPUT TYPE text NAME city P INPUT TYPE checkbox NAME retired I am retired FORM FORM INPUT TYPE button NAME act VALUE Verify onClick verifyIt FORM BODY HTML Figure 23-2 The elements array helps find text fields for validation. CD-474 Part VI Appendixes encoding enctype NN2 NN3 NN4 NN6 IE3 J1 IE3 J2 IE4 IE5 Compatibility Example If you need to modify the first form in a document so that the content is sent in non-URL-encoded text at the user s request the .

TỪ KHÓA LIÊN QUAN