• Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint

Using Text Controls

We’ve already seen a good deal about text controls in this book, so we can skip the elementary aspects of using the value property and so on. The onchange event is a useful one JavaScript programmers should know about. This event occurs when the user has changed the text in a text control and “committed” the change by moving the focus away from the control (as by clicking another control). Here’s an example putting onchange to work—when the user enters text into the text field and then clicks outside the text field, the text from the text field is displayed in a <DIV> element (like other examples that use getElementById, you’ll need NS6+ if you’re using the Netscape Navigator):

(Listing 13-02.html on the web site)

<HTML> 
    <HEAD> 
        <TITLE>Using the onchange Event</TITLE> 
        <SCRIPT LANGUAGE="JavaScript"> 
            <!--
            function displayText()
					{
					document.getElementById("div1").innerHTML =
					"The text field holds: " + document.form1.text1.value
					} 
            //--> 
        </SCRIPT> 
    </HEAD> 

    <BODY> 
        <H1>Using the onchange Event</H1> 
        <FORM NAME="form1"> 
            <INPUT TYPE="TEXT" NAME="text1" ONCHANGE="displayText()"> 
            <BR> 
            <DIV ID="div1"> 
        </FORM> 
    </BODY> 
</HTML> 

					  


PREVIEW

                                                                          

Not a subscriber?

Start A Free Trial


  
  • Creative Edge
  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • PrintPrint