[Zope] Returning and showing value of a checkbox

Schmidt, Allen J. aschmidt@nvcc.edu
Wed, 22 Jan 2003 07:07:10 -0500


"Checkboxes don't have a value attribute." ??? 

Since when? 
I've been using values on checkboxes since I have been building web
forms....going on 10 years now... adding checked only determines whether it
is checked or not be default when the form loads. If you have a bunch all
named the same and several are checked, they are handled as a list of values
with the name of "listname" or whatever you call it.

Unless I have been using it wrong all this time...but it works like this now
for me on many, many forms. And works well...

-----Original Message-----
From: zope-admin@zope.org [mailto:zope-admin@zope.org]On Behalf Of Dylan
Reinhardt
Sent: Tuesday, January 21, 2003 8:55 PM
To: zope@zope.org
Subject: RE: [Zope] Returning and showing value of a checkbox


At 05:02 PM 1/21/2003, Don Brooksby wrote:
> > I have even tried to do:
> > <td><input type="checkbox" name="newmain" value="<dtml-var main>"></td>

Checkboxes don't have a value attribute.  They are either checked or not 
checked.

Your two options are:

<input type=checkbox name=whatever checked>
<input type=checkbox name=whatever>

That's all they do, other attributes will be ignored.

In your template file, insert the string "checked" into your tag if the 
value corresponding to this box is true.  If it isn't, don't.  The code to 
do that in DTML and ZPT was posted earlier.

When you process the form, use something like the following to get the 
value of your checkbox:

my_box_value = REQUEST.form.get('my_checkbox_name', 0)

If the box isn't checked, the name of the box may not be posted to your 
processing script.  In that case, get() provides a not-found value of zero, 
corresponding to a "false" value you'd want to have received from an 
un-clicked checkboxes.

Does that help?

Dylan


_______________________________________________
Zope maillist  -  Zope@zope.org
http://lists.zope.org/mailman/listinfo/zope
**   No cross posts or HTML encoding!  **
(Related lists - 
 http://lists.zope.org/mailman/listinfo/zope-announce
 http://lists.zope.org/mailman/listinfo/zope-dev )