Check if checkbox is checked or unchecked in perl

Posted on 2005-03-02
Medium Priority
Last Modified: 2011-10-03
i have this perl page that connects to ms access db using DBI

it display the values from  the db fields in a table.

the last field is yes/no datatype and i need to check if it is checked or unchecked.

$db = DBI->connect( "dbi:ODBC:PerlLink","","",{RaiseError => 1, printError => AutoCommit => 1})
or die "Unable to connect: " .$DBI::errstr . "\n";

$query = $db->prepare("SELECT * FROM tblData");


$numrows = $query->rows;

print "<table border=1><tr><th>Record ID</th><th>Firstname</th><th>Lastname</th><th>Address</th><th>Age</th><th>Contact Number</th><th>Confirmed</th></tr>\n";

while (@array = $query->fetchrow_array)

                in here i need a perl script to check if the yes/no datatype field is checked or unchecked
                the yes/no field is called confirmed      


             my ($record_id, $firstname, $lastname, $address, $age, $contact, $confirmed) = @array;
             print "<tr><td>$record_id</td><td>$firstname</td><td>$lastname</td><td>$address</td><td>$age</td><td>$contact</td>" ;
             print "<form name=\"formcheckbox\"><td align=\"center\"><input type=\"checkbox\" name=\"confirmed\" value=0 onClick=\"SubmitForm(this, $record_id);\" $confirmed></td></form>" ;
print "</table>";

if this is unclear, please state so asap, so i can explain better as this problem is very urgent now and needs a solution
Question by:ellandrd
LVL 16

Expert Comment

ID: 13438595
What you can do is print the value of $confirmed.
When I tested this, it returns 1 or 0 depending on whether the checked or not.

LVL 18

Accepted Solution

kandura earned 2000 total points
ID: 13440664

            ### CHECKED is the html attribute to turn a checkbox on
            my $confirmed_yn = $confirmed ? 'checked' : '';  

            ### change $confirmed to $confirmed_yn here:
            ### (and also, I would set the value to $confirmed (so that it will hold 1 or 0)
            print "<form name=\"formcheckbox\"><td align=\"center\"><input type=\"checkbox\" name=\"confirmed\" value=0 onClick=\"SubmitForm(this, $record_id);\" $confirmed></td></form>" ;
LVL 85

Expert Comment

ID: 13440819
           my ($record_id, $firstname, $lastname, $address, $age, $contact, $confirmed) = @array;
             $confirmed ||= '';
             $confirmed &&= "checked";
            print "<tr><td>$record_id</td><td>$firstname</td><td>$lastname</td><td>$address</td><td>$age</td><td>$contact</td>\n";
            print qq{<form name="formcheckbox"><td align="center"><input type="checkbox" name="confirmed" value=0 onClick="SubmitForm(this, $record_id);" $confirmed></td></form>\n} ;

Featured Post

Take Control of Web Hosting For Your Clients

As a web developer or IT admin, successfully managing multiple client accounts can be challenging. In this webinar we will look at the tools provided by Media Temple and Plesk to make managing your clients’ hosting easier.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

On Microsoft Windows, if  when you click or type the name of a .pl file, you get an error "is not recognized as an internal or external command, operable program or batch file", then this means you do not have the .pl file extension associated with …
There are many situations when we need to display the data in sorted order. For example: Student details by name or by rank or by total marks etc. If you are working on data driven based projects then you will use sorting techniques very frequently.…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Six Sigma Control Plans
Suggested Courses

588 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question