Checkbox


A checkbox contains a small box that can be checked or unchecked, either by the user or programmatically. It also has a text label.

The syntax to create a checkbox is as follows:

CHECKBOX #handle, labelExpr$, setting - Add a checkbox to the web page using #handle, labelExpr$ and setting

If the value for setting is nonzero, the checkbox is displayed with a checkmark. If the value for setting is 0, the checkbox is created unchecked.

CHECKBOX methods

#handle SET(booleanExpr) - Set or reset the checkbox according to booleanExpr
#handle VALUE() - Return a booleanExpr indicating if the checkbox is set or reset
#handle ISNULL() - Returns zero (or false)
#handle DEBUG$() - Returns the string "Checkbox"

The following demo creates a checkbox that is initially clear, or unset. Clicking the link activates a routine that demonstrates the VALUE() method to determine the checked state of the checkbox. The result is printed on the page.

CHECKBOX #ch, "Option", 0
print ""
link #get, "Get Checkbox Value", [getCheck]
wait
 
[getCheck]
isSet = #ch value()
if isSet then
print:print "Checkbox is checked."
else
print:print "Checkbox is clear."
end if
wait

The following demo creates a checkbox and attempts to toggle the checked state programmatically. The checkbox can be set, but it cannot be reset (cleared.)

CHECKBOX #ch, "Option", 0
print ""
link #get, "Toggle Check", [toggleCheck]
wait
 
[toggleCheck]
isSet = #ch value()
if isSet then
print:print "Checkbox is set."
'clear checkmark
#ch SET(0)
else
print:print "Checkbox is unset."
'add checkmark
#ch SET(1)
end if
wait

This code demonstrates the Debug$() and IsNull() methods.

print "Before creation, IsNull() returns:"
print #ch isnull()
print
CHECKBOX #ch, "Option", 0
print
print "Object is a ";#ch debug$()
print
print "After creation, IsNull() returns:"
print #ch isnull()
wait

Practical implementation of checkbox.

[start]
cls
checkbox #ch1, "Option 1", 0
checkbox #ch2, "Option 2", 0
checkbox #ch3, "Option 3", 0
print:print
link #get, "Get Checkbox Value", [getCheck]
print
wait
 
[getCheck]
for n=1 to 3
ch$="#ch";n
isSet = #ch$ value()
print "Checkbox ";n;
if isSet then
print " is checked."
else
print " is clear."
end if
next n
print
link #nxt, "Again?", [again]
wait
[again]
goto [start]

And vertically aligned checkboxes.

[start]
cls
checkbox #ch1, "Option 1", 0
print
checkbox #ch2, "Option 2", 0
print
checkbox #ch3, "Option 3", 0
print:print
link #get, "Get Checkbox Value", [getCheck]
print
wait
 
[getCheck]
for n=1 to 3
'note handle variable!
ch$="#ch";n
isSet = #ch$ value()
print "Checkbox ";n;
if isSet then
print " is checked."
else
print " is clear."
end if
next n
print
link #nxt, "Again?", [again]
wait
[again]
goto [start]