PRB: Value of a Checkbox Interpreted Differently

ID: Q186422


The information in this article applies to:
  • Microsoft Internet Explorer (Programming) versions 3.02, 4.01, 5.0


SYMPTOMS

The following VBScript code produces different results when viewed by Internet Explorer 3.02 and Internet Explorer 4.01 or later (the full text of the HTML and VBScript code will be detailed in the next section):


<SCRIPT LANGUAGE="VBScript">
<!--
   sub submit_onclick
   if document.Info.sound.checked = True then msgbox "The checkbox is
   checked!"
   end sub
   -->
</SCRIPT> 
Internet Explorer 3.02 does not interpret the value of the checkbox correctly. As a result, it does not execute the action in the THEN section of the IF/THEN statement.


CAUSE

Following is a full HTML and VBScript example:

Sample Code


<HTML>
<HEAD>
<TITLE>Checkbox test </TITLE>
</HEAD>
<BODY>
<FORM NAME="Info">
<center>
My test checkbox
<input name="sound" type="checkbox">
<INPUT value="Test the checkbox value" TYPE="button" NAME="CheckIt"
ALIGN=left>
<SCRIPT LANGUAGE="VBScript">
<!--
sub CheckIt_onclick
if document.Info.sound.checked = true then msgbox "The checkbox is checked!"
end sub
-->
</SCRIPT>
</FORM>
</BODY>
</HTML> 
The VBScript Language Reference defines "True" as the value -1. Internet Explorer 3.02 incorrectly interprets "True" as 1. For example:

if document.Info.sound.checked = -1 then msgbox "The checkbox is clicked!"

if document.Info.sound.checked = 1 then msgbox "The checkbox is clicked!" 
The first line displays the message box correctly when you view it with Internet Explorer 4.01 or later, but not with Internet Explorer 3.02. Conversely, the second line displays the message box correctly when you use Internet Explorer 3.02, but not Internet Explorer 4.01 or later.


RESOLUTION

You can display the message box correctly in both versions of Internet Explorer by removing the explicit comparison to a value (True, 1 or -1) and allowing Internet Explorer to implicitly evaluate the statement. For example:


if document.Info.sound.checked then msgbox "The checkbox is checked!" 
By doing this, it is implied that document.Info.sound.checked is evaluated to True or False. VBScript makes the comparison correctly.


MORE INFORMATION

Steps to Reproduce Behavior

  1. View the previous HTML code with Internet Explorer 3.02 and Internet Explorer 4.01 or later.


  2. Select the check box.


  3. Click the button.


  4. Note that the same code produces different results in each browser.


Additional query words: kbDSupport kbdsi kbIE302 kbIE401

Keywords : kbIE500
Version : WINDOWS:3.02,4.01;
Platform : WINDOWS
Issue type : kbprb


Last Reviewed: May 7, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.