Celcius Posted November 24, 2011 Share Posted November 24, 2011 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 More sharing options...
teynon Posted November 26, 2011 Share Posted November 26, 2011 The value of a checkbox is the value... <input type="checkbox" name="checkboxName" value="Value"> You can use ajax or just javascript. Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1291262 Share on other sites More sharing options...
Celcius Posted December 1, 2011 Author Share Posted December 1, 2011 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. Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1293145 Share on other sites More sharing options...
teynon Posted December 1, 2011 Share Posted December 1, 2011 Perhaps you should be using their name as their name? <input type="checkbox" name="names[DB_NAME_ID]" value="value"> Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1293154 Share on other sites More sharing options...
Celcius Posted December 1, 2011 Author Share Posted December 1, 2011 But then, when I post the data, I need to retrieve the value on action page. So I can get their name and preform some DB queries. Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1293202 Share on other sites More sharing options...
teynon Posted December 1, 2011 Share Posted December 1, 2011 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> Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1293207 Share on other sites More sharing options...
Celcius Posted December 2, 2011 Author Share Posted December 2, 2011 Is there a method where I can perform some action when a checkbox is checked? Basically, if checkbox checked, totalPoints += points Link to comment https://forums.phpfreaks.com/topic/251747-adding-point-totals-from-a-checkbox/#findComment-1293295 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.