tcl-rivet-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Massimo Manghi <>
Subject using 'load_response' with checkboxes
Date Thu, 15 Feb 2007 10:45:26 GMT
Hi fellow tclers ,

I'm using 'load_response' to handle the data being passed in
by a form where several checkboxes are used. I don't know
if i'm using checkboxes in an orthodox way but I
would like to have a list containing the lines numbers
for which  the corresponding checkbox is checked.

'load_response' seemed to do it well at first.

load_response is a very simple procedure and basically
builds an array in this way 

    array set response {}

    foreach {var elem} [var all] {
        if {[info exists response($var)]} {
            set response($var) [list $response($var) $elem]
        } else {
            set response($var) $elem

I think the first branch in the if statement would be better as

set response($var) [concat $response($var) $elem]

the difference between [list ....] and  [concat ...] is lesson 2 of Tcl
and I'm sure you have already imagined the effects of having 'list'
instead of 'concat'

example: I want the element 'oid' of the response to be set with
the list of the "value"  attributes for which for checkbox is checked

   <input type="checkbox" name="oid" value="v1"> Line 1 </input><br/>
   <input type="checkbox" name="oid" value="v2"> Line 2 </input> <br/>
   <input type="checkbox" name="oid" value="v3"> Line 3 </input> <br/>
   <input type="checkbox" name="oid" value="v4"> Line 4 </input> <br/>
if 2 ckeckboxes are checked (say checkbox 1,3 ) the array element is

response(oid) = v1 v3

which is correct. When 3 checkboxes are checked (say 1,3,4) the array is

response(oid) = {v1 v3} v4

Having more checkboxes results in a proportionally convoluted
list of nested lists.

-- Massimo Manghi 

-- Dipartimento di Biologia Evolutiva e Funzionale 
-- Università degli Studi di Parma
-- Parco Area delle Scienze 11A - 43100 Parma

To unsubscribe, e-mail:
For additional commands, e-mail:

View raw message