Jump to content

Recommended Posts

Hello,

 

I want to be able to total up the point values at the bottom of my table.

My HTML table is pretty simple

 

+----------+------+--------+

| CHECKBOX | NAME | POINTS |

+----------+------+--------+

 

The value of the check box is the NAME and the POINTS, is a floating point number (3 decimals max)

Now when a user checks a box, I want to add the value of the points in the related row to the total and display it at the bottom in a cell underneath the point column.

I thought ajax would be the right tool for this job.

Any ideas on how to do this?

I was going to give it a go, but since the value of the checkbox is the name and not the point value, I was stumped from the start.

 

Link to comment
https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/
Share on other sites

The value of a checkbox is the value...

 

<input type="checkbox" name="checkboxName" value="Value">

 

You can use ajax or just javascript.

 

Hahaha, right, but that is not what I meant.

 

The value="Value" is not the point value, it's the name of the person associated with that checkbox.  Each checkbox is two different things a name and a point value. However, I am already using the value part for their name.

Go to http://tomsfreelance.com/phpfreaks/postExample.php and post the form.

 

This is the code:

 

<?php
if (isset($_POST['doForm'])) {
    echo "<pre>";
    print_r($_POST);
    echo "</pre>";
    
    foreach ($_POST['list'] as $database_user_id => $value) {
        $sql = "UPDATE `tablename` SET `fieldname` = '{$value}' WHERE id = '{$database_user_id}'";
        echo $sql;
    }
}
?>

<html>
    <head>
        <title>Titties</title>
    </head>
    <body>
        <form name="blah" action="#" method="POST">
            <input type="checkbox" id="list[12]" name="list[12]" value="2.356" checked> <label for="list[12]">User 12 (2.356)</label>
            <input type="submit" name="submit" value="Submit">
            <input type="hidden" name="doForm" value ="1">
        </form>
    </body>
</html>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.