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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T06:40:21+00:00 2026-06-10T06:40:21+00:00

I have a series of rows in a table each with different values (prices)

  • 0

I have a series of rows in a table each with different values (prices) and each row has a checkbox. This table is generated through a PHP loop.

echo "<table border='0' cellpadding='10' id='booking-list'><tr>";
echo "<th>Booking ID</th><th>Customer ID</th><th>Start Date</th><th>Course Name</th><th>Amount Due</th><th>Date Payment Due</th><th>Add to basket</th></tr>";
$x = 0; 
while ($row = mysql_fetch_assoc($query)) {
    $balance = $row['price'] - $row['deposit'];

    echo "<td>" .$row['booking_id']. "</td><td>" .$cust_id. "</td><td>" .$row['start_date']. "</td><td>" .$row['name']. "</td><td>" .$balance. "</td><td>" .$row['balance_due_date']. "</td><td><input type='checkbox' name='' value='" .$x. "' /></td></tr>";
    $x++;
}
echo "</tr><table>";

For every check box that is checked, I’d like to add (.append) the specific value ($balance) to a form input field. The appending part seems to be working but I’m not sure how to loop through each checked checkbox in jQuery to grab the value I need.

function(){
    $('#booking-list input:checkbox').change(
        function(){
            if ($(this).is(':checked')) {
        $('<input />').attr({
                type: 'text',
            id: 'foo',
            name: 'bar',
        value: '<?php echo $balance; ?>'
        }).appendTo('#paypal-form form').text($(this).val());              
            } else {
                $('#paypal-form input:contains('+$(this).val()+')').remove();
            }
        }); 

Right now, I can only get the last $balance value generated.

Thanks.

  • 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-10T06:40:22+00:00Added an answer on June 10, 2026 at 6:40 am

    You are using $balance after the loop, that’s why you are only getting the last value.

    To use the value directly in the event handler, you would have to create a separate event handler for each checkbox inside the loop. Instead you can put the balance value in the data for the checkbox:

    <input type='checkbox' name='' value='" .$x. "' data-balance='" .$balance. "' />
    

    Then you can use it in the event handler:

    value: $(this).data('balance')
    

    Side note: Right now you only have code for adding inputs, so if someone checks something and then unchecks it, the input is still there.

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

Sidebar

Related Questions

I have a series of table rows like this: <cfloop query=qryPlayer> (...snip...) <input data-playerid=#PlayerID#
i have a series of rows that are generated using an asp:repeater : <asp:repeater
I have a view that displays a table: rows represent days - one row
I have some script that is delivering a series of rows from an SQL
I have a series of PHP page, and I would like to use conditional
I have a series of if statements in a function like this: if time
I have a series of... pseudo-xml files. What I mean by this, is they
I have a series of strings (URLs) in different forms as: http://domain name.anything/anypath https://dmain
I have a series of select boxes within a table like so: <tr> <td><select></select></td>
I have a 300.000 rows table; one of the columns is a varchar() but

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.