php - Dynamically adding the values of a checkbox that has been inserted dynamically? -


how dynamically display sum of values of check boxes have been checked in php.

its checkout in shopping cart.each item checked, has value , final amount(in same page @ bottom) should sum of rates of items have been checked(without refreshing).

i may need use ajax. can give simple sample code please

for checkboxes, need make them array, instance:

<input type="checkbox" name="items[]" id="items[]" value="25" /><br /> <input type="checkbox" name="items[]" id="items[]" value="40" /><br /> <input type="checkbox" name="items[]" id="items[]" value="12" /><br /> ... <!-- many want --> <input type="checkbox" name="items[]" id="items[]" value="20" /><br /> 

on php side handle so...(note: come php array)

$items = $_post["items"]; //it's array -- feel free var_dump($items) see content //to sum $total_amount = array_sum($items); //but advise cleaning values first 

and yes, can achieve same if submit form using ajax (e.g. via jquery)
happy coding :)


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -