Notice: This website is an unofficial Microsoft Knowledge Base (hereinafter KB) archive and is intended to provide a reliable access to deleted content from Microsoft KB. All KB articles are owned by Microsoft Corporation. Read full disclaimer for more details.

HOW TO: Change the State of an HTML Control Based on the Value of Another HTML Control


View products that this article applies to.

This article was previously published under Q315604

↑ Back to the top


Summary

This step-by-step article demonstrates how to use object events to handle user interaction with Web page elements. In this article, you create a sample that handles the onPropertyChange event to take action when the user selects or clears a check box.

Dynamic Hypertext Markup Language (DHTML) provides an extensive object model for Hypertext Markup Language (HTML) and exposes all Web page elements as objects that can be scripted. You can manipulate DHTML objects to change style attributes or other properties for Web page elements with script. With DHTML, you can handle user interaction with Web page elements by means of object events.

Requirements

The following list outlines the recommended hardware, software, network infrastructure, and service packs that are required:
  • Internet Explorer 5.5 or later
This article assumes that you are familiar with the following topics:
  • HTML
  • DHTML

Detect the Property Change Event

  1. Open a text editor such as Notepad.
  2. Add the following code to the file:
    <HTML>
    <BODY>
      <P/><INPUT Type="checkbox" CHECKED ID="Check1"/>
      <P/><INPUT Type="text" ID="Text1"/>
    </BODY>
    <SCRIPT Language="VBScript">
      Function Check1_OnPropertyChange()
        Text1.Disabled = Not(Check1.Checked)
      End Function
    </SCRIPT>
    </HTML>
    					
  3. Save the file as C:\PropChangeDemo.htm.

Verify That It Works

  1. Start Internet Explorer.
  2. Type C:\PropChangeDemo.htm in the Address bar. The HTML page contains a check box and a text box. Notice that the check box is selected and that the text box is empty.
  3. Type any text in the text box to verify that the text box is enabled.
  4. Click to clear the check box. This fires the onPropertyChange event. The event handler method in the HTML page disables the text box.
  5. Try to type additonal text in the text box. Notice that you cannot type any text because the text box is disabled.
  6. Click to select the check box. This fires another onPropertyChange event. The event handler method enables the text box.
  7. Type additional text in the text box. Notice you can type text now because the text box is enabled again.

↑ Back to the top


References

For more information about developing Web-based solutions for Microsoft Internet Explorer, visit the following Microsoft Web sites:

↑ Back to the top


Keywords: KB315604, kbhowtomaster, kbhowto

↑ Back to the top

Article Info
Article ID : 315604
Revision : 3
Created on : 4/21/2006
Published on : 4/21/2006
Exists online : False
Views : 271