Welcome to Dream.In.Code
Getting Help is Easy!

Join 86,247 Programmers. There are 2,227 online right now! Ask your question and get quick answers from Dream.In.Code experts. Join the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert
Powered by LivePerson.com

Register to Make This Box Go Away!

reading from checkboxes in perl

 
Reply to this topicStart new topic

reading from checkboxes in perl

orangebulb
post 15 Apr, 2008 - 06:12 PM
Post #1


New D.I.C Head

*
Joined: 8 Apr, 2008
Posts: 18



I need to use an if statement to see whether or not a checkbox is checked. I'm not sure how you do that in perl. For example, if a checkbox has the value set to "1" can I say if $variable == 1 ? I'm just really kind of confused on how to do that. Because doesn't the checkbox hold that value whether or not it's checked?

Any help is greatly appreciated. smile.gif
User is offlineProfile CardPM
Go to the top of the page
+Quote Post


girasquid
post 15 Apr, 2008 - 06:22 PM
Post #2


Barbarbar

Group Icon
Joined: 3 Oct, 2006
Posts: 953

I find that in situations like these, it's easiest to just write a quick piece of code to test what you think it does - if it doesn't do that, come back and tell us and we'll help you figure it out. smile.gif
User is online!Profile CardPM
Go to the top of the page
+Quote Post

fahlyn
post 15 Apr, 2008 - 07:29 PM
Post #3


New D.I.C Head

*
Joined: 3 Nov, 2007
Posts: 41

if you're using CGI.pm you can do something like this...

CODE

use CGI;
my $q = CGI->new;
if($q->param('checkboxName')){
    #do whatever here
}


The key is that if a check box isn't checked it will not be submitted as part of the form.

Hope that helps.
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

KevinADC
post 16 Apr, 2008 - 12:25 AM
Post #4


D.I.C Head

Group Icon
Joined: 23 Jan, 2007
Posts: 168

QUOTE(fahlyn @ 15 Apr, 2008 - 07:29 PM) *

if you're using CGI.pm you can do something like this...

CODE

use CGI;
my $q = CGI->new;
if($q->param('checkboxName')){
    #do whatever here
}


The key is that if a check box isn't checked it will not be submitted as part of the form.

Hope that helps.



The checkbox name/value pair will still be transmited, but it will have no value. CGI forms have no awarness of blank fields, which is why they are unable to verify themselves and you have to use javascript or server side validation to see if a form field is filled in with something.

Your code is checking that the form field has a true value, something besides "" (empty) or 0 (zero).
User is offlineProfile CardPM
Go to the top of the page
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 5/16/08 08:43AM

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month