CD-382 Part VI . Appendixes Example Use The (Web server application)

CD-382 Part VI . Appendixes Example Use The Evaluator to test out the getElementsByName()method. All form elements in the upper part of the page have names associated with them. Enter the following statements into the top text field and observe the results: document.getElementsByName( output ) document.getElementsByName( speed ).length document.getElementsByName( speed )[0].value You can also explore all of the properties of the text field by typing the following expression into the bottom field: document.getElementsByName( speed )[0] getSelection() NN2 NN3 NN4 NN6 IE3/J1 IE3/J2 IE4 IE5 IE5.5 Compatibility Example The document in Listing 18-15 provides a cross-browser (but not IE5/Mac) solution to capturing text that a user selects in the page. Selected text is displayed in the textarea. The script uses browser detection and branching to accommodate the diverse ways of recognizing the event and reading the selected text. Listing 18-15: Capturing a Text Selection Getting Selected Text