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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T17:34:03+00:00 2026-06-13T17:34:03+00:00

I have a jQuery function that takes the value from a PHP-generated check box

  • 0

I have a jQuery function that takes the value from a PHP-generated check box and sends it over AJAX. The value is always a single word with nothing but letters by the way. Below is the script.

<script type="text/javascript">
    $(document).ready(function() {
        $("input:checkbox").on("click", function () {
            step = this.value;
            //document.getElementById("test").innerHTML = step;
            responseArray = [];

            xmlhttp=new XMLHttpRequest();
            xmlhttp.onreadystatechange=function() {
                if (xmlhttp.readyState==4 && xmlhttp.status==200) {
                    responseArray = eval("(" + xmlhttp.responseText + ")");
                    document.getElementById("test").innerHTML = responseArray;
                }
            }

            xmlhttp.open("GET", "checkbox.php?step="+step, true);
            xmlhttp.send();
        });
    });
</script>

The above code results in the “ReferenceError: [this.value] is not defined”. [this.value] is the actual value though which changes based on the box that is checked. If you notice the 5th line in the above code, when I don’t comment that line out it displays the correct value in “test” for the step variable, so it’s something after that. Below is the checkbox.php file completely simplified down to basically nothing and it still causes the error.

<?php       
    $step = $_GET["step"];
    echo "[" . $step . "]";
?>
  • 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-13T17:34:04+00:00Added an answer on June 13, 2026 at 5:34 pm

    As I can see your using Jquery, you should use JQuery’s AJAX object. It simplifies the request a lot:

    $.ajax({
      url: 'checkbox.php?step=',
      success: function(data) {
        alert(data);
      }
    });
    

    http://api.jquery.com/jQuery.ajax/

    Now your problem seems to be that you’re not getting the value of the checkbox through properly. Checkboxes are either on or off. Here’s how to get the various parameters:

    $(document).ready(function () {
        $("input:checkbox").on("click", function () {
            var checkboxID = $(this).attr("ID");        // Returns the ID of the checkbox
            var isChecked = $(this).is(':checked');     // Returns true or false
    
            alert($(this).attr("ID") + " is " + isChecked);
        });
    });
    

    So your final code might look something like:

    $(document).ready(function () {
        $("input:checkbox").on("click", function () {
            var checkboxID = $(this).attr("ID");        // Returns the ID of the checkbox
            var isChecked = $(this).is(':checked');     // Returns true or false
    
            $.ajax({
               url: 'checkbox.php?step=' + isChecked ,
               success: function(data) {
                 alert(data);
               }
             });
        });
    });
    

    (untested code) which would send a request to the url checkbox.php?step=true

    And hello from 2+2 😀

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

Sidebar

Related Questions

I have a jquery-ajax function that sends data to a php script and the
I have a function called Colorbox (jQuery plugin) that takes a number of parameters
I have some jQuery that takes the value of a text input and puts
I have this jquery post that takes text from a textarea and inputs it
I have a Jquery that takes the value of a checkbox as soon as
i have the following jquery code. basically - it takes a value from an
I have this code that takes info from a form and sends it to
I have javascript function that get JSON from another php file but I can't
I have this jquery function that works, except I need to add something. I
I have a jQuery function that replaces thumbnails with the main image. This is

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.