Chapter 13. Working with Text and Select Controls


graphics/chic01.gif

In this chapter, we'll take a look at the HTML text and select controls. That includes more than you might thinktext fields, password controls, hidden controls, text areas, select controls, option elements, option group elements, and so on. All these controls are central to any JavaScript programmer's arsenal, so what we see here will be a good part of our JavaScript foundation, just as working with button controls was in the preceding chapter.

For example, it's hard to imagine a substantial JavaScript-based web page that accepts text input from a user without using text fields. We've worked with this basic control since Chapter 1, "Essential JavaScript," both to display and read text, and we're no strangers to code like this, which displays a message, You clicked the button! , in a text field when the user clicks a button:

(Listing 13-01.html on the web site)
 <HTML>      <HEAD>          <TITLE>              Executing Scripts in Response to User Action          </TITLE>          <SCRIPT LANGUAGE="JavaScript">              <!--  function alerter()   {   document.form1.text1.value = "You clicked the button!"   }  // -->          </SCRIPT>      </HEAD>      <BODY>          <H1>Executing Scripts in Response to User Action</H1>          <FORM NAME="form1">  <INPUT TYPE="BUTTON" ONCLICK="alerter()" VALUE="Click Me!">   <INPUT TYPE="TEXT" NAME="text1" SIZE="30">  </FORM>      </BODY>  </HTML> 

You can see this code at work in Figure 13.1. That was easy enough; but what about working with selected text in text controls, or working with text areas? And what about handling user selections in select controlsor even multiple selections? We'll see all of that in this chapter. In fact, besides text fields, password controls, and hidden controls, we'll also see another of the <INPUT> controls <INPUT TYPE="FILE"> , the file upload controlwhich enables you to upload a file to the server.

Figure 13.1. Using a text field in the Netscape Navigator.

graphics/13fig01.gif



Inside Javascript
Inside JavaScript
ISBN: 0735712859
EAN: 2147483647
Year: 2005
Pages: 492
Authors: Steve Holzner

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net