Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I programically uncheck a checkbox in an HTA?

Status
Not open for further replies.

wchull

MIS
Jun 14, 2001
93
US
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:progid:DXImageTransform.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>
 
Where in your code did you expect a change for FieldCheckbox ?

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
The code in the sample is just a stubbed out verion of the program. If you run it and check the checkbox it will display a message box indicating that the box was checked. If you then presss the button what should happen is that a second message box should indicate that the check box was still checked but the next statement should cause the check box to become unchecked. Repeatedly pressing the button should casuse the checkbox to be checked and then unchecked.
 
And what about this ?
If Form.FieldCheckbox.Checked Then
MsgBox ("When button pushed, checkbox was checked")
form.fieldcheckbox.value = False
Else
MsgBox ("When button pushed, checkbox was unchecked")
form.fieldcheckbox.value = True
End If

Hope This Helps, PH.
Want to get great answers to your Tek-Tips questions? Have a look at FAQ219-2884 or FAQ181-2886
 
DM4EVER:

Thanks for the great hint! The corect answer was:

document.getElementById("cb1").checked=False
document.getElementById("cb1").checked=True

Everything is working now. Much Thanks!!!!!!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top