How can I code to get more than One value from checkbox?

Steve Holden steve at holdenweb.com
Thu Sep 30 19:29:10 EDT 2004


Shufen wrote:

> Hi,
> 
> I'm a newbie that just started to learn python, html and etc. I have
> some questions to ask and hope that someone can help me on.
> 
> I'm trying to code a python script (with HTML) to get values from a
> html form that consists of about 10 checkbox and a textbox where user
> have to key in a value to perform a search.
> 
> From python tutors, I learned that I have to use the following method:
> 
> ###
> qtype = data.getfirst('qtype')       ---- checkbox name
> qtext = data.getfirst('qtext', '')   ---- textbox name
> ###
> 
> but I don't really know how to do it. Should I use qtype =
> data.getlist('qtype') to get the value from the checkbox and how to?
> 
> 
> Currently, my method required me to type in every possible combination
> of the checkbox and I know that this is wrong. I wanna to include
> %(qtype) in my query statement so that the script will look for the
> value that contain qtype everytime a form is processs but the way I'm
> doing now is wrong.
> 
> query = "select %(qtype)s from shot_descriptions where
> shot_number=%(qtext)s", qtype, qtext
> 
> 
> Thus, can someone help me on this.
> 
> Thank you for any help.
> 
> Shufen

I think you're confusing checkboxes and radio buttons.

If you have ten different boxes that can be checked, each will usually 
have a different name, so you can test them with data.getfirst("box1"), 
data.getfirst("box2"), and so on.

While it's true that you can have several checkbox elements with the 
same name, and that the CGI interface will give you a list of such 
values, there's absolutely no need to do so and, as you have discovered, 
it's positively unhelpful in most cases.

With radio buttons, you give each member of the set the same name in 
your HTML and the browser submits the value of only the one that's been 
checked (if one has).

regards
  Steve



More information about the Python-list mailing list