Checkbox

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**


 * 1) handle SET(booleanExpr) //- Set or reset the checkbox according to booleanExpr//
 * 2) handle VALUE //- Return a booleanExpr indicating if the checkbox is set or reset//
 * 3) handle ISNULL //- Returns zero (or false)//
 * 4) 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.

code format="vbnet" 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 code

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.)

code format="vbnet" 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 else print:print "Checkbox is unset." 'add checkmark end if wait code
 * 1) ch SET(0)
 * 1) ch SET(1)

This code demonstrates the **Debug$** and **IsNull** methods.

code format="vbnet" 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 code

Practical implementation of checkbox.

code format="vbnet" [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] code

And vertically aligned checkboxes.

code format="vbnet" [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] code