Programming Forums
User Name Password Register
 

RSS Feed
FORUM INDEX | TODAY'S POSTS | UNANSWERED THREADS | ADVANCED SEARCH

Reply
 
Thread Tools Display Modes
Old Sep 19th, 2005, 8:08 AM   #1
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
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
MegaArcon is offline   Reply With Quote
Old Sep 19th, 2005, 8:28 AM   #2
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 19th, 2005, 8:32 AM   #3
ChiHappens
Programmer
 
ChiHappens's Avatar
 
Join Date: Sep 2005
Location: Brevard, NC
Posts: 35
Rep Power: 0 ChiHappens is an unknown quantity at this point
Send a message via MSN to ChiHappens
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
__________________
http://www.starshipcombatsimulator.com
They mostly come at night...mostly.
ChiHappens is offline   Reply With Quote
Old Sep 19th, 2005, 8:46 AM   #4
DaWei
Resident Grouch
 
DaWei's Avatar
 
Join Date: Jun 2005
Posts: 6,453
Rep Power: 10 DaWei is on a distinguished road
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
DaWei is offline   Reply With Quote
Old Sep 19th, 2005, 8:48 AM   #5
ChiHappens
Programmer
 
ChiHappens's Avatar
 
Join Date: Sep 2005
Location: Brevard, NC
Posts: 35
Rep Power: 0 ChiHappens is an unknown quantity at this point
Send a message via MSN to ChiHappens
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.
__________________
http://www.starshipcombatsimulator.com
They mostly come at night...mostly.
ChiHappens is offline   Reply With Quote
Old Sep 19th, 2005, 9:39 AM   #6
MegaArcon
Programmer
 
MegaArcon's Avatar
 
Join Date: Aug 2005
Posts: 66
Rep Power: 0 MegaArcon is an unknown quantity at this point
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
MegaArcon is offline   Reply With Quote
Reply

Bookmarks

« Previous Thread in Forum | Next Thread in Forum »

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump




DaniWeb IT Discussion Community
All times are GMT -5. The time now is 3:47 AM.

Powered by vBulletin® Version 3.7.0, Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Copyright ©2007 DaniWeb® LLC