Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6714379
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T08:29:21+00:00 2026-05-26T08:29:21+00:00

Try this at home: Write a form to display a list of checkboxes in

  • 0

Try this at home:
Write a form to display a list of checkboxes in PHP:

$checkboxes = array('one' => 1, 'two' => 2, 'three' => 3);
$html = "<html><body><form name=\"myForm\" action=\"this\" method=\"post\"><ul>Check Test";

foreach ($checkboxes as $id => $value)
{
     $checkVal = (isset($_POST['check_test'][$id])) ? 'true' : 'false';
     $checkList = "<li><input type=\"checkbox\" name=\"check_test[]\" id=\"$id\"
                   value =\"$value\" checked=\"$checkVal\" />$name = $value</li>\n";
}
$checkList .= "<input type=\"submit\" value=\"Submit\">";
echo $html.$checkList."</ul></body></html>";

You will find that no matter what you put into the $checkVal assignment, when you hit submit, your checkboxes will all be checked. My workaround is to expand the $checkVal variable to set the entire “checked=” status to either something or nothing. I’m just surprised that Firefox (rather, Iceweasel) is only looking to see if the attribute is set at all. Why even have it if whatever it’s set to is irrelevant?

Look at the source html. The selected attribute will display whatever you put into the checkval variable. The DOM specification states:
checkboxObject.checked=true|false

Here is my output:

<ul><li><input type="checkbox" name="check_test[]" id="one"
                       value ="1" checked="false" />one= 1</li>
    <li><input type="checkbox" name="check_test[]" id="two"
                       value ="2" checked="false" />two= 2</li>
    <li><input type="checkbox" name="check_test[]" id="three"
                       value ="3" checked="false" />three= 3</li>

And lo and behold! Every box is checked. Contrary to what I’ve explicitly expressed in the html.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T08:29:22+00:00Added an answer on May 26, 2026 at 8:29 am

    The false is ignored. If the check attribute exists the box is checked.

    foreach ($checkboxes as $id => $value)
    {
         $checkVal = (isset($_POST['check_test'][$id])) ? 'checked="checked"' : '';
         $checkList = "<li><input type=\"checkbox\" name=\"check_test[]\" id=\"$id\"
                       value =\"$value\" ".$checkVal." />$name = $value</li>\n;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got home yesterday and decided to try and write a scheme program that
Hi I have an array like this: array( 'Home' => array( 'About', 'Contact' ),
please try this link for getting my code. its working in all browsers not
I try this command to upload a file (standard.xml) into table book the file
I try this with NetBeans desktop application template - increasing heapsize (to 512 MiB)
When I try this code: dict_a = dict_b = dict_c = {} dict_c['hello'] =
When I try this code: if Verbose: print("Building internam Index for %d tile(s) ..."
If I try this statement: INSERT INTO TerminalEventChild (id,stringValue) VALUES (64,'version123|'); MySQL fail with
it s the first time i try this page. I ve just installed imagemagick
I want to make this 1332251639632 to this 1332251639 I try this code, but

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.