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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T04:02:13+00:00 2026-05-23T04:02:13+00:00

So I have a to-do list of items that are dynamically populated by user

  • 0

So I have a to-do list of items that are dynamically populated by user input. Each has a checkbox next to it, when checked, the status of the to-do item in MySQL database should be modified.

I thought of doing it this way:

echo "<input type='checkbox' onclick='changeState($theid);' />";

where $theid is the row id in the table.

What would the javascript/jquery changeState() function look like to be able to update the database properly?

Here is the javascript code that seems to not work at all (it is placed in the <head> of the HTML file:

<script language="javascript">

function changeState()
{
    jQuery('body').delegate('input[type="checkbox"][data-state-id]', 'change', function(event){
    jQuery.post('updatedata.php', {
        'rowid': jQuery(this).attr('data-state-id')
        //'state': jQuery(this).is(':checked')
    });
});

}

</script>

any ideas why?

  • 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-23T04:02:14+00:00Added an answer on May 23, 2026 at 4:02 am

    You should read more about AJAX calls, preferably with .post() function, and then update the data in database on the server side.

    Good luck.

    Based on the examples from the documentation of jQuery’s .post(), you can implement something like this (in JavaScript with jQuery):

    var changeStatus = function(id){
        $.post("updateState.php", { 'id': id } );
    };
    

    and on the server side (eg. in updateState.php):

    $id = (int)$_POST['id'];
    // here make some query using $id to update the state
    // in a manner you prefer
    

    EDIT:

    But I would prefer something like that:

    1) on server side, displaying the checkbox (notice different quotes and (int) cast):

    echo '<input type="checkbox" data-state-id="' . (int)$theid . '" />';
    

    2) somewhere in JavaScript (see jsfiddle as a proof):

    jQuery(main_container).delegate('input[type="checkbox"][data-state-id]', 'change', function(event){
        jQuery.post('update_state.php', {
            'id': jQuery(this).attr('data-state-id'),
            'state': jQuery(this).is(':checked')
        });
    });
    

    3) somewhere on server side (in update_state.php):

    $id = (int)$_POST['id'];
    $state = (bool)$_POST['state'];
    $query = 'UPDATE `states` SET `state`="' . $state . '" WHERE `id`="' . $id . '";';
    // here execute the query, obviously adjusted to your needs
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

My goal is to have a list of items each item has an image
I have a list of items that a user can add to by clicking
I have a list of items on my web page that the user can
I have a ListView in my project that has dynamically added/edited/deleted items. When the
I have a list of tab items that have views dynamically added to them.
I have a list of items that is dynamically pulled from a web service.
I have a flex spark list that is populated by a dynamically generated ArrayCollection
I have a list of items that I need to update on different intervals.
I have a list of items that are displayed using a ListView from a
I have a list of items that are created from the results of website

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.