I have an HTA with embedded VBScript and I have a situation where if the user checks a checkbox and another condition exists I need to display an error message and then uncheck the check box. I have sample code that does not include a FORM and it appears that all that is going ton is to set the value of the checkbox to TRUE and the box should become unchecked. My problem is that with FORM specified with the variable (i.e. form.fieldcheckbox.value) the program does not error but the checkbox value never changes. Here is some sample code. If someone can tell me what I'm doing wrong I would be very grateful.
<HEAD>
<TITLE>Test Form</TITLE>
</HEAD>
<body STYLE="font:14pt arial; color:black;
filter
rogid
XImageTransform.Microsoft.Gradient
(GradientType=0, StartColorStr='#339900', EndColorStr='#CCFFCC')">
<FORM NAME="testForm">
<HTA:APPLICATION
ID = "DHCPREQ"
APPLICATIONNAME = "Test Form"
>
<center><Table Border =2>
<TR><Center>
<td COLSPAN=6><center><Font face="arial" size="2pt"><input type="checkbox" id="CB1" name="FieldCheckbox" onclick=SetNumServers()> Field should be changing.</TD></Center></TR>
</Table></Center>
<P><Font face="arial" size="2pt"><Center><INPUT TYPE="BUTTON" SIZE=50 NAME="Finished" VALUE="Change" ></Font></CENTER>
</FORM>
</BODY>
</HTML>
<SCRIPT LANGUAGE="VBSCRIPT">
<!-- Option Explicit
Sub SetNumServers()
Dim form
Set form = document.testform
If Form.FieldCheckbox.Checked Then
MsgBox ("Box was checked")
End If
End Sub
Sub Finished_OnClick()
Dim form
Set form = document.testform
If Form.FieldCheckbox.Checked Then
MsgBox ("When button pushed, checkbox was checked")
form.fieldcheckbox.value = True
Else
MsgBox ("When button pushed, checkbox was unchecked")
form.fieldcheckbox.value = False
End If
End Sub
-->
</SCRIPT>
</BODY>
</HTML>
<HEAD>
<TITLE>Test Form</TITLE>
</HEAD>
<body STYLE="font:14pt arial; color:black;
filter
(GradientType=0, StartColorStr='#339900', EndColorStr='#CCFFCC')">
<FORM NAME="testForm">
<HTA:APPLICATION
ID = "DHCPREQ"
APPLICATIONNAME = "Test Form"
>
<center><Table Border =2>
<TR><Center>
<td COLSPAN=6><center><Font face="arial" size="2pt"><input type="checkbox" id="CB1" name="FieldCheckbox" onclick=SetNumServers()> Field should be changing.</TD></Center></TR>
</Table></Center>
<P><Font face="arial" size="2pt"><Center><INPUT TYPE="BUTTON" SIZE=50 NAME="Finished" VALUE="Change" ></Font></CENTER>
</FORM>
</BODY>
</HTML>
<SCRIPT LANGUAGE="VBSCRIPT">
<!-- Option Explicit
Sub SetNumServers()
Dim form
Set form = document.testform
If Form.FieldCheckbox.Checked Then
MsgBox ("Box was checked")
End If
End Sub
Sub Finished_OnClick()
Dim form
Set form = document.testform
If Form.FieldCheckbox.Checked Then
MsgBox ("When button pushed, checkbox was checked")
form.fieldcheckbox.value = True
Else
MsgBox ("When button pushed, checkbox was unchecked")
form.fieldcheckbox.value = False
End If
End Sub
-->
</SCRIPT>
</BODY>
</HTML>