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

  • SEARCH
  • Home
  • 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 6055965
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T08:19:25+00:00 2026-05-23T08:19:25+00:00

I have an array of checkboxes name=box[]. Through PHP I make sure that they’re

  • 0

I have an array of checkboxes name=”box[]”. Through PHP I make sure that they’re checked after they’re submitted by echoing “checked=’checked'” if they were checked at submit event.

Now, if I check the third box, the value jumps down to the first checkbox after submit, since the array was empty up until the third checkbox. Same, if I check the 2nd and 3rd checkbox, they jump down to 1st and 2nd after submit. This is the code I’m using:

<form method="post">
    <input type="checkbox" name="box[]" value="true" <?php if ($box[0] == true) echo "checked='checked'"; ?>><br>
    <input type="checkbox" name="box[]" value="true" <?php if ($box[1] == true) echo "checked='checked'"; ?>><br>
    <input type="checkbox" name="box[]" value="true" <?php if ($box[2] == true) echo "checked='checked'"; ?>><br>
    <p>
    <input type="submit" value="Submit">
</form>

Try it at:
http://experiencerapanui.com/selecttest.php

Can I make the checkboxes fill up the array with a value “false” or whatever, if the box is unchecked? Which way should I go?

****** EDIT ******

Thanks to phant0m, I managed to come up with a solution:

<form method="post">
    <input type="checkbox" name="box[]" value="1" <?php if (in_array("1", $box)) echo "checked='checked'"; ?>><br>
    <input type="checkbox" name="box[]" value="2" <?php if (in_array("2", $box)) echo "checked='checked'"; ?>><br>
    <input type="checkbox" name="box[]" value="3" <?php if (in_array("3", $box)) echo "checked='checked'"; ?>><br>
    <p>
    <input type="submit" value="Submit">
</form>

Putting unique values for the checkboxes, then if I find the value in the array $box[], the box is marked as checked.

  • 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-23T08:19:25+00:00Added an answer on May 23, 2026 at 8:19 am

    This does not work, because only those checkboxes, that are checked, are being put into the $box array.

    Either use different names, or different values to distinguish between them.

    Consider this: You check the second and the third checkbox. In PHP, you will receive:

    $_POST['box'] = array(0 => "true", 1 => "true");
    

    You cannot know, which checkboxes have been checked, unless all of them are.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array of checkboxes that I edit at once to set up
Hi I have an array of checkboxes e.g. <input type=checkbox name=checks[] value=1 /> <input
If I have a form with two checkboxes that have have the same array
I have array of select tag. <select id='uniqueID' name=status> <option value=1>Present</option> <option value=2>Absent</option> </select>
I am going nuts here, I have an array of checkboxes from a form
I have a that has a list of checkboxes and user can click any
I have a bunch of checkboxes each with a unique name and value using
I have a list of checkboxes that I want to insert into a database,
Hi I have the following page: <input type=checkbox name=fruit1 id=1 class=box>Banana<br /><br /> <input
I have checkboxes in my form, which returns me string instead of array, as

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.