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 8305547
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T18:08:22+00:00 2026-06-08T18:08:22+00:00

I have an issue that I ‘m trying to solve. I searched in internet

  • 0

I have an issue that I ‘m trying to solve. I searched in internet but nothing helped me.. I have multiple groups of checkboxes and I want to get their values and pass them in db. The problem is that only the first checkbox of group gets the right value. Here is my code :

Html code :

<tr>
        <th>Δημοτικός Κήπος</th>
        <td align="center">
            <span style="display:none;">
                <input type="checkbox" name="place1[]" value="1" id="place1_1"/>
            </span>
            <img id="Imageplace1_1" 
            src="unchecked.jpg" 
            width="35" 
            height="35" 
            onclick="CheckBoxClicked('place1_1')" 
            style="cursor:pointer;"/>
        </td>
        <td align="center">
            <span style="display:none;">
                <input type="checkbox" name="place1[]" value="2" id="place1_2"/>
            </span>
            <img id="Imageplace1_2" 
            src="unchecked.jpg" 
            width="35" 
            height="35" 
            onclick="CheckBoxClicked('place1_2')" 
            style="cursor:pointer;"/>
        </td>
        <td align="center">
            <span style="display:none;">
                <input type="checkbox" name="place1[]" value="3" id="place1_3"/>
            </span>
            <img id="Imageplace1_3" 
            src="unchecked.jpg" 
            width="35" 
            height="35" 
            onclick="CheckBoxClicked('place1_3')" 
            style="cursor:pointer;"/>
        </td>
        <td colspan="2" align="center">
            <span style="display:none;">
                <input type="checkbox" name="place1[]" value="4" id="place1_4"/>
            </span>
            <img id="Imageplace1_4" 
            src="unchecked.jpg" 
            width="35" 
            height="35" 
            onclick="CheckBoxClicked('place1_4')" 
            style="cursor:pointer;"/>
        </td>
    </tr>

php code :

    if(isset($_POST['answeres'])) {
        $place1[0] = (@$_POST['place1'][0]=='1')? $_POST['place1'][0]:'0';
        $place1[1] = (@$_POST['place1'][1]=='1')? $_POST['place1'][1]:'0';
        $place1[2] = (@$_POST['place1'][2]=='1')? $_POST['place1'][2]:'0';
        $place1[3] = (@$_POST['place1'][3]=='1')? $_POST['place1'][3]:'0';
        echo $place1[0]; //I get 1 if checked 0 if unchecked
        echo $place1[1]; //I get 0 all the time
        echo $place1[2]; //I get 0 all the time
        echo $place1[3]; //I get 0 all the time
    }                

javascript code :

var CheckBoxCheckedImage = new Image();
var CheckBoxUncheckedImage = new Image();


CheckBoxCheckedImage.src = "checked.jpg";
CheckBoxUncheckedImage.src = "unchecked.jpg"; 

function CheckBoxClicked(CheckBoxid) {

    if(document.getElementById(CheckBoxid).value == "on"){
    //if(document.getElementById(CheckBoxid).checked) {
        document.getElementById(CheckBoxid).checked = false;
        document.getElementById("Image"+CheckBoxid).src = CheckBoxUncheckedImage.src;
    }
    else{
        document.getElementById(CheckBoxid).checked = true;
        document.getElementById("Image"+CheckBoxid).src = CheckBoxCheckedImage.src;     
    }
}

Can anyone help? I can’t figure it out….

  • 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-06-08T18:08:23+00:00Added an answer on June 8, 2026 at 6:08 pm

    2 Mistakes:

    1) In your PHP you check if the value of the checkbox is 1 or not, but in your HTML the values of the checkboxes are 1, 2, 3, 4. So either you set the checkboxes’ values all to 1 in your HTML or you check against 1 thru 4 in your PHP – depending on what you want and how you decide to solve your 2nd mistake.

    2) When checkboxes are posted only those checkboxes are part of the $_POST array that are checked. This means that $_POST['place1'][0] will be the first checked checkbox and not necessarily the first checkbox in the form with that name. You can solve this by using keys in the checkbox-name (name="place1[0]", name="place1[1]" and so on) or by using different values for each checkbox and checking against the values instead of against the keys (hints: look at in_array(), array_values())

    Other hints:

    • use print_r($_POST); so see what actually is posted to the PHP script – makes debugging a lot easier.
    • Do not use @ to supress errors/notices: It’s slow. It’s bad coding (errors should be avoided, notices should be taken care of – instead of supressing them).
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an issue that I've spent hours trying to figure out, but since
I have an issue that (I think) might have to do with scope, but
So I have an issue that I'm not 100% sure on how to solve.
I have an issue that i am having trouble to solve. We are about
I have this issue that I want to resolve. Lets think we have this
I have an issue that I can't seem to solve. I am randomly generating
I have one issue that i want to ping URL from code behind (EXE
I have an issue that I can't solve by myself. The best thing would
I have a issue that i want your inouts on. I have a outer
I have an issue that I am lost on how to solve. In my

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.