checkbox values in cherrypy
I understand that Cherrypy makes checkbox value开发者_Go百科s available as a list cfg question (CherryPy - saving checkboxes selection to variables)
Let's say I have following form data:
... snip ...
<input type=checkbox id="1">
<input type=checkbox id="1">
<input type=checkbox id="1">
<input type=checkbox id="2">
<input type=checkbox id="2">
<input type=checkbox id="2">
<input type=checkbox id="3">
<input type=checkbox id="3">
<input type=checkbox id="3">
... snip ...
Then Cherrypy makes this available as:
{'1': [u'on', u'on', u'on'],'2': [u'on', u'on', u'on'],'3': [u'on', u'on', u'on']}
From the moment I uncheck the second checkbox id3 then I get:
{'1': [u'on', u'on', u'on'],'2': [u'on', u'on', u'on'],'3': [u'on', u'on']}
With this I'm unable to say which checkbox is unchecked, .... I could when 'off' would be used when a checkbox is unchecked.. but that's not the case.
Any ideas how to tackle this?
Cheers,
Jay
First a nit: The "id" attribute in HTML is supposed to be unique for the whole document.
You then have two options:
- Change the "name" attributes to be unique, like
<input type="checkbox" name="3b">
, in which case you'll get back{..., '3a': u'on' '3c': u'on'}
, or - Make the values unique, like
<input type="checkbox" name="3" value="b">
, in which case you'll get back{..., '3': [u'a', u'c']}
.
精彩评论