I am bignner in using JQuery with PHP, I have a form that culcalate the sum by using JQuery and displayed into HTML form, then I want to take this value from the form and inserted to the database by using PHP.

Could any body help me

HTML code:


      <td style="border:1px solid #ccc; border-width:1px 1px 0 0;"><span id="sum5">0</span></td>


JQuery code:


        //iterate through each textboxes and add keyup
        //handler to trigger sum event
        $(".txtt").each(function() {



    function calculateSum() {

        var sum5 = 0;
        //iterate through each textboxes and add the values
        $(".txtt").each(function() {

            //add only if the value is number
            if(!isNaN(this.value) && this.value.length!=0) {
                sum5 += parseFloat(this.value);

        //.toFixed() method will roundoff the final sum to 2 decimal places


You use a hidden field for store this total value in your form.Like

<input type="hidden" name="hdnTotal" id="hdnTotal" value="" />

And also add the below code in your calculateSum().


In your action page you will get the total value as

  $_POST['hdnTotal'] //if you use post methode
  $_GET['hdnTotal'] // if you user get methode

I've not tested this but I don't think you need to iterate your selectors to add the keyup event handler. You should be able to use the following code:-

$(".txtt").keyup(function() {