Dealing with HTML checkbox return values
Checkboxes are a special creature in the HTML world. They require special handling.
When a checkbox is checked, it passes on its VALUE property to the web server - as you would expect. The problem is that when it is UNchecked, nothing passed to the web server indicates that checbox ever existed! It's as if the checkbox was never there!
So if you check for the existence of the object value and the object does not exist, you can surmise that the checkbox was un-checked. This works, but it encourages developers to hard-code their logic for checkboxes - which is a drag if your checkboxes vary from user to user, or if you add or remove checkbox options.
A better solution is to use the same logic that generated your checkboxes in the first place to create a list of POSSIBLE checkbox values. You can then scan through the possible checkbox names and check for the existence of each.
Here's an example of how I generate the checkboxes on one of my HTML forms (using West-Wind WebConnect):
lcNotifyBoxes = []
SELECT Services.*, MenuTitle ;
FROM .\Condo\LinkSvcs, .\Condo\Services ;
WHERE Services.SvcCode=LinkSvcs.SvcCode ;
AND LinkSvcs.PropCode = lcCondoCode ;
AND AccessLvl <= lnAccessLvl ;
AND !EMPTY(NotifyCode);
ORDER BY OrderCode ;
INTO CURSOR TLocalQuery
IF _TALLY>0
lnColCount=INT(_TALLY/3) && For creating three columns
lcNotifyBoxes=[<table width="100%" border="0">]+CR+[<tr>]+CR+[<td>]
lnDummy=0
SCAN
IF TLocalQuery.NotifyCode = [H] AND VAL(lnPosition) < 22
&& Keep work req notification out for non-board members
ELSE
lcNotifyBoxes=lcNotifyBoxes+;
[<input type="checkbox" name="]+TLocalQuery.SvcCode+[" value="Yes" class="chkbox"]+;
IIF(TLocalQuery.NotifyCode $ lnNotifyList," checked","")+[>]+TLocalQuery.MenuTitle+[<br>]
IF lnDummy=lnColCount
lcNotifyBoxes=lcNotifyBoxes+[</td>]+CR+[<td>]
lnDummy=0
ELSE
lnDummy=lnDummy+1
ENDIF
ENDIF
ENDSCAN
lcNotifyBoxes=lcNotifyBoxes+[</td>]+CR+[</tr>]+CR+[</table>]+CR
ENDIF
So let's use the same SQL Select in order to create a cursor to scan, and determine the values of the checkboxes: SELECT Services.*, MenuTitle ;
FROM .\Condo\LinkSvcs, .\Condo\Services ;
WHERE Services.SvcCode=LinkSvcs.SvcCode ;
AND LinkSvcs.PropCode = lcCondoCode ;
AND AccessLvl <= lnAccessLvl ;
AND !EMPTY(NotifyCode);
ORDER BY OrderCode ;
INTO CURSOR TLocalQuery
IF _TALLY>0
SCAN
IF Request.IsFormVar(TLocalQuery.SvcCode) AND “Y“ $ Request.Form(TLocalQuery.SvcCode)
* Value is checked (second check above is probably not necessary)
WAIT WINDOW TLocalQuery.SvcCode + [ is CHECKED]
ELSE
* Value is NOT checked
WAIT WINDOW TLocalQuery.SvcCode + [ is NOT checked]
ENDIF
ENDSCAN
ENDIF

Links to this post:
<< Home