This topic is locked
[SOLVED]

 Custom Total

8/4/2011 3:37:28 AM
PHPRunner General questions
H
hsan author

Cristian,
You were kind enough to help me throughout...I have one more question. Is it possible to create a custom (non-DB)field at the bottom of list page that will calculate sum (from the "Price" field) of all selected records?
Thanks

C
cgphp 8/4/2011

I give you some hints:

  • Place a custom field (a textbox or a label) where you want to show the total
  • Specify an id for the new field
  • In the javascript onload event for each selected record increment a var with the price value of the selected record and show the total in the custom field

H
hsan author 8/4/2011



I give you some hints:

  • Place a custom field (a textbox or a label) where you want to show the total
  • Specify an id for the new field
  • In the javascript onload event for each selected record increment a var with the price value of the selected record and show the total in the custom field


That is good enough. Thanks a lot.

H
hsan author 8/5/2011



That is good enough. Thanks a lot.


Christian,
I've created custom label with id 'total' but I cannot figure out how to retrieve value of 'price' field for a selected row in list view. I would appreciate your further help.
Thanks

C
cgphp 8/5/2011
var sum = 0;

$("input[type='checkbox']").click(function(e){

var price = parseFloat($(this).parents().eq(1).find("td span[id*='your_price_field_name']").text());



if($(this).is(":checked"))

sum += price;

else

sum -= price;



$("#total").text(sum);

});


Not tested!

H
hsan author 8/5/2011


var sum = 0;

$("input[type='checkbox']").click(function(e){

var price = parseFloat($(this).parents().eq(1).find("td span[id*='your_price_field_name']").text());

if($(this).is(":checked"))

sum += price;

else

sum -= price;

});
$("#total").text(sum);


Not tested!


Cristian,
Inputbox stays blank, no errors in firebug. When I inspect Inputbox with firebug, it shows "0" as value (as you set in var sum=0;), but it does not display in browser.

C
cgphp 8/5/2011

Inputbox ?? You said a label not a inputbox. Where do you want to write the sum, in a inputbox (textbox) or in a label ?

H
hsan author 8/5/2011



Inputbox ?? You said a label not a inputbox. Where do you want to write the sum, in a inputbox (textbox) or in a label ?


I tried both, same results. I would like to read sum in label.
Thanks

C
cgphp 8/5/2011

Nash,
my fault. Try this code:

var sum = 0;

$("input[type='checkbox']").click(function(e){

var price = parseFloat($(this).parents().eq(1).find("td span[id*='your_price_field_name']").text());



if($(this).is(":checked"))

sum += price;

else

sum -= price;



$("#total").text(sum);

});


I have moved $("#total").text(sum); inside the click event.

C
cgphp 8/5/2011
var sum = 0;

$("input[type='checkbox']").click(function(e){

var price = parseFloat($(this).parents().eq(1).find("td span[id*='Price']").text().replace("$",""));

if($(this).is(":checked"))

sum += price;

else

sum -= price;



$("#total").val('$' + sum);

});
H
hsan author 8/5/2011


var sum = 0;

$("input[type='checkbox']").click(function(e){

var price = parseFloat($(this).parents().eq(1).find("td span[id*='Price']").text().replace("$",""));

if($(this).is(":checked"))

sum += price;

else

sum -= price;
$("#total").val('$' + sum);

});



Yup, this is it, big thanks to Cristian!