![]() |
|
![]() |
|
|
Thread Tools | Display Modes |
|
|
#1 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
Checkboxs in a form
Hi all,
I've got a problem that I'm having a bitl of trouble solving. Looking for some help. Basicly, I've got a cgi script written that will take dynamic input from stdin, parse it, and create an arbitrary number of checkboxes with the "name" attribue set to an integer baised on the input. This integer could be anything from 1 to who knows what. On the page that it produces, I want to write a cgi script that will do something with all the checked checkboxs when the user hits a "submit" button, but I don't know how to go about checking for, and handling an unknown number and unknown names of checkboxs. Can anyone help? Thanks a bunch! Gord |
|
|
|
|
|
#2 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Consider array syntax.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#3 |
|
Programmer
|
the information that comes from a form submission is usually name value combinations. So you should be able to use a while loop and get each pair. You could also have a hidden field that signifies eof or could even hold the number of boxes in it's value and then you could use a For loop.
Hope this helps, Chi |
|
|
|
|
|
#4 |
|
Resident Grouch
![]() ![]() ![]() ![]() ![]() ![]() Join Date: Jun 2005
Posts: 6,453
Rep Power: 10
![]() |
Name/value pairs are not sent for unchecked boxes.
__________________
Abstraction doesn't make it impossible to write bad code; it makes it possible to write superior code. Contributor's Corner: Grumpy on C++ Exceptions DaWei on Pointers |
|
|
|
|
|
#5 |
|
Programmer
|
right, DaWei...but he didn't say he wanted to know anything about the unchecked ones. If he does want to handle everything on the form, he can use JavaScript on the client side to iterate through the DOM.
|
|
|
|
|
|
#6 |
|
Programmer
Join Date: Aug 2005
Posts: 66
Rep Power: 0
![]() |
Thanks guys! I've managed to figure it out. I gave every checkbox the same name, and gave the value attribute the unknown integer. I can get the list, single or no checked item with the following code fragment:
#returns either a list, singe item, or None TheList = form.getvalue('name') #check to see if a list was returned if isinstance(TheList, list): do_stuff_with_a_list() #else, it is a single item else: do_stuff_with_single_item_or_no_item() This will only get the values of the checked boxes. Thanks a bunch all! Gord |
|
|
|
![]() |
| Bookmarks |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
|
|