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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T16:19:52+00:00 2026-06-15T16:19:52+00:00

I have some checkbox values that I generate as $sql = sql statement; $courseResult

  • 0

I have some checkbox values that I generate as

$sql = "sql statement";
$courseResult = mysqli_query($connection, $sql);
$courses = mysqli_fetch_row($
// Display the courses the user has taken 
while ($courses) {
    echo "<td><input type='checkbox' name='coursesToAdd[]' id='coursesToAdd[]' value='$courses[0]'>$courses[0]</td></tr>";            
    $courses = mysqli_fetch_row($courseResult);
}

<input type='button' onclick='EditStudentCertificates()' value='Submit'/>

what i want to do is get the values that the user checks into an array, and than access this array from javascript which i was trying to do as such, but it does not seem to work:

        function EditStudentCertificates(){                
            if (window.XMLHttpRequest){
                // code for IE7+, Firefox, Chrome, Opera, Safari                
                xmlhttp=new XMLHttpRequest();
            }
            else{
                // code for IE6, IE5
                xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
            }      

            var coursesToAddField = document.getElementById("coursesToAdd[]");
            var coursesToAdd = coursesToAddField ? coursesToAddField.value : '';

            xmlhttp.open("POST","updateStudentCInfo.php",true);
            xmlhttp.setRequestHeader("Content-type","application/x-www-form-urlencoded");
            xmlhttp.send("certValue="+certValue+"&coursesToAdd="+coursesToAdd);
            window.alert("Your certificate information has been updated");
            window.location.reload();                
        }

What i think the problem is is something with the way i trying to get the values from the checkboxs in the javascript, possibly something with:

            var coursesToAddField = document.getElementById("coursesToAdd[]");
            var coursesToAdd = coursesToAddField ? coursesToAddField.value : '';

Because the variable coursesToAdd doesnt seem to hold anything but the value of the first checkbox on the page no matter how many checkboxes i check on the page before hitting submit.

  • 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-15T16:19:53+00:00Added an answer on June 15, 2026 at 4:19 pm

    As I mentioned in my comment above:

    Without even looking at the AJAX code you posted, you are having a problem with the way you get the values from the checkboxes. You are using the same id coursesToAdd[] to all checkboxes. That is invalid, as all ids need to be unique on the page. You need to use a classname instead.

    In your HTML/PHP:

    while ($courses) {
        echo "<td><input type='checkbox' name='coursesToAdd[]' class='coursesToAdd' value='$courses[0]'>$courses[0]</td></tr>";            
    }
    

    And in your JS you can get to the checkboxes like this:

    var courseCheckboxes = document.getElementsByClassName("coursesToAdd");
    for (var i=0; i < courseCheckboxes.length; i++) {
        if (courseCheckboxes[i].checked) {
           // do something with the checkbox
        }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have inserted this form with multiple checkbox items which collects some values, What
I have datagridview with checkbox column, but I want, that some of the columns
I have some object (div, input/checkbox) in an HTML page. The values for their
I have some values that post back to a parent form from a child
I'm trying to create a preferences window. In it I have some checkbox style
I have a fieldset in which I have some input fields and a checkbox.
I have a checkbox which in some cases may be disabled and checked using
I have some arbitrary pixel data that I want to save as a PNG.
I have some text lines like that : vt_wildshade2^508^508 vt_ailleurs2^1188^1188 ... vt_high2^13652^13652 Is it
My datagridview has a checkbox column that is only valid for some records in

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.