How to Insert input text from datatables to database and multiply 2 values, pass that value to input box in...












0















I have list of products in datatables in html included with 3 input box and check box in it
you can refer to the screen shot



enter image description here



as per the picture i should enter price and quantity, Automatically total should calculated like




Price: 12 Quantity: 2 Total: 24




total should automatically added but how to do in the table and those values should insert into database at least i need in Json formate



Like



[{flower_id: 1, flower_price: 12, flower_quantity: 2, total: 24},{flower_id: 2, flower_price: 2, flower_quantity: 20, total: 40},]



here is the table



<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>Flower Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>#</th>
</tr>
</thead>
<tbody>

<?php
foreach ($flowers as $value) {
?>
<tr>
<td><?= $value->flower_name ?></td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="flower_price" class="flower_price">
</td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="quantity" class="quantity">
</td>
<td class="text-right">
<input type="text" class="form-control" name="total_price" class="total_price">
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" onclick="customerCheckBox()" name="flower_id" value="<?= $value->id ?>">
</label>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>


here is the Javascript file



                                                                    function customerCheckBox() {
var selected = new Array();
$("input:checkbox[name = flower_id]:checked").each(function () {
selected.push({flower_id: $(this).val()});
});

$("input[name=flower_price]").each(function () {
if ($(this).val()) {
selected.push({flower_price: $(this).val()});
}
});

$("input[name=quantity]").each(function () {
if ($(this).val()) {
selected.push({quantity: $(this).val()});
}
});
if (selected.length > 0) {
document.getElementById("product").value = JSON.stringify(selected);
}
}

function getValue() {
var flower = $('input[name=flower_price').val();
var qunatity = $('input[name=quantity').val();
var result = (flower * qunatity);
$('input[name=total_price').val(result);
}


i need like this if i click the checkbox, so that i can pass this Json to submit form to insert into database what to do?



Thanks in advance










share|improve this question

























  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 7:29











  • I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

    – Hossam
    Nov 24 '18 at 8:25











  • i just updated the code, you can check it, i am using php as backend, yes am using javascript

    – Gss Venkatesh
    Nov 24 '18 at 10:32
















0















I have list of products in datatables in html included with 3 input box and check box in it
you can refer to the screen shot



enter image description here



as per the picture i should enter price and quantity, Automatically total should calculated like




Price: 12 Quantity: 2 Total: 24




total should automatically added but how to do in the table and those values should insert into database at least i need in Json formate



Like



[{flower_id: 1, flower_price: 12, flower_quantity: 2, total: 24},{flower_id: 2, flower_price: 2, flower_quantity: 20, total: 40},]



here is the table



<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>Flower Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>#</th>
</tr>
</thead>
<tbody>

<?php
foreach ($flowers as $value) {
?>
<tr>
<td><?= $value->flower_name ?></td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="flower_price" class="flower_price">
</td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="quantity" class="quantity">
</td>
<td class="text-right">
<input type="text" class="form-control" name="total_price" class="total_price">
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" onclick="customerCheckBox()" name="flower_id" value="<?= $value->id ?>">
</label>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>


here is the Javascript file



                                                                    function customerCheckBox() {
var selected = new Array();
$("input:checkbox[name = flower_id]:checked").each(function () {
selected.push({flower_id: $(this).val()});
});

$("input[name=flower_price]").each(function () {
if ($(this).val()) {
selected.push({flower_price: $(this).val()});
}
});

$("input[name=quantity]").each(function () {
if ($(this).val()) {
selected.push({quantity: $(this).val()});
}
});
if (selected.length > 0) {
document.getElementById("product").value = JSON.stringify(selected);
}
}

function getValue() {
var flower = $('input[name=flower_price').val();
var qunatity = $('input[name=quantity').val();
var result = (flower * qunatity);
$('input[name=total_price').val(result);
}


i need like this if i click the checkbox, so that i can pass this Json to submit form to insert into database what to do?



Thanks in advance










share|improve this question

























  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 7:29











  • I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

    – Hossam
    Nov 24 '18 at 8:25











  • i just updated the code, you can check it, i am using php as backend, yes am using javascript

    – Gss Venkatesh
    Nov 24 '18 at 10:32














0












0








0








I have list of products in datatables in html included with 3 input box and check box in it
you can refer to the screen shot



enter image description here



as per the picture i should enter price and quantity, Automatically total should calculated like




Price: 12 Quantity: 2 Total: 24




total should automatically added but how to do in the table and those values should insert into database at least i need in Json formate



Like



[{flower_id: 1, flower_price: 12, flower_quantity: 2, total: 24},{flower_id: 2, flower_price: 2, flower_quantity: 20, total: 40},]



here is the table



<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>Flower Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>#</th>
</tr>
</thead>
<tbody>

<?php
foreach ($flowers as $value) {
?>
<tr>
<td><?= $value->flower_name ?></td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="flower_price" class="flower_price">
</td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="quantity" class="quantity">
</td>
<td class="text-right">
<input type="text" class="form-control" name="total_price" class="total_price">
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" onclick="customerCheckBox()" name="flower_id" value="<?= $value->id ?>">
</label>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>


here is the Javascript file



                                                                    function customerCheckBox() {
var selected = new Array();
$("input:checkbox[name = flower_id]:checked").each(function () {
selected.push({flower_id: $(this).val()});
});

$("input[name=flower_price]").each(function () {
if ($(this).val()) {
selected.push({flower_price: $(this).val()});
}
});

$("input[name=quantity]").each(function () {
if ($(this).val()) {
selected.push({quantity: $(this).val()});
}
});
if (selected.length > 0) {
document.getElementById("product").value = JSON.stringify(selected);
}
}

function getValue() {
var flower = $('input[name=flower_price').val();
var qunatity = $('input[name=quantity').val();
var result = (flower * qunatity);
$('input[name=total_price').val(result);
}


i need like this if i click the checkbox, so that i can pass this Json to submit form to insert into database what to do?



Thanks in advance










share|improve this question
















I have list of products in datatables in html included with 3 input box and check box in it
you can refer to the screen shot



enter image description here



as per the picture i should enter price and quantity, Automatically total should calculated like




Price: 12 Quantity: 2 Total: 24




total should automatically added but how to do in the table and those values should insert into database at least i need in Json formate



Like



[{flower_id: 1, flower_price: 12, flower_quantity: 2, total: 24},{flower_id: 2, flower_price: 2, flower_quantity: 20, total: 40},]



here is the table



<table id="datatables" class="table table-striped table-no-bordered table-hover" cellspacing="0" width="100%" style="width:100%">
<thead>
<tr>
<th>Flower Name</th>
<th>Price</th>
<th>Quantity</th>
<th>Total</th>
<th>#</th>
</tr>
</thead>
<tbody>

<?php
foreach ($flowers as $value) {
?>
<tr>
<td><?= $value->flower_name ?></td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="flower_price" class="flower_price">
</td>
<td class="text-right">
<input type="text" onblur="getValue()" class="form-control" name="quantity" class="quantity">
</td>
<td class="text-right">
<input type="text" class="form-control" name="total_price" class="total_price">
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" onclick="customerCheckBox()" name="flower_id" value="<?= $value->id ?>">
</label>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>


here is the Javascript file



                                                                    function customerCheckBox() {
var selected = new Array();
$("input:checkbox[name = flower_id]:checked").each(function () {
selected.push({flower_id: $(this).val()});
});

$("input[name=flower_price]").each(function () {
if ($(this).val()) {
selected.push({flower_price: $(this).val()});
}
});

$("input[name=quantity]").each(function () {
if ($(this).val()) {
selected.push({quantity: $(this).val()});
}
});
if (selected.length > 0) {
document.getElementById("product").value = JSON.stringify(selected);
}
}

function getValue() {
var flower = $('input[name=flower_price').val();
var qunatity = $('input[name=quantity').val();
var result = (flower * qunatity);
$('input[name=total_price').val(result);
}


i need like this if i click the checkbox, so that i can pass this Json to submit form to insert into database what to do?



Thanks in advance







javascript json






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 24 '18 at 10:19







Gss Venkatesh

















asked Nov 24 '18 at 7:24









Gss VenkateshGss Venkatesh

12010




12010













  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 7:29











  • I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

    – Hossam
    Nov 24 '18 at 8:25











  • i just updated the code, you can check it, i am using php as backend, yes am using javascript

    – Gss Venkatesh
    Nov 24 '18 at 10:32



















  • Have you tried anything?

    – Shail Paras
    Nov 24 '18 at 7:29











  • I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

    – Hossam
    Nov 24 '18 at 8:25











  • i just updated the code, you can check it, i am using php as backend, yes am using javascript

    – Gss Venkatesh
    Nov 24 '18 at 10:32

















Have you tried anything?

– Shail Paras
Nov 24 '18 at 7:29





Have you tried anything?

– Shail Paras
Nov 24 '18 at 7:29













I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

– Hossam
Nov 24 '18 at 8:25





I didn't get what you want. You want to calculate the total, the checkbox is used for what exactly? You are using JavaScript, right? What is the backend you are using?

– Hossam
Nov 24 '18 at 8:25













i just updated the code, you can check it, i am using php as backend, yes am using javascript

– Gss Venkatesh
Nov 24 '18 at 10:32





i just updated the code, you can check it, i am using php as backend, yes am using javascript

– Gss Venkatesh
Nov 24 '18 at 10:32












1 Answer
1






active

oldest

votes


















0














Here is the solution



Javascript



function customerCheckBox($id) {
var selected = new Array();
var flowerPrice = $('#flower_price_' + $id).val();
var qunatity = $('#quantity_' + $id).val();
var totalPrice = $('#total_price_' + $id).val();
var selected = {flower_id: $id, flower_price: flowerPrice, qunatity: qunatity,
total_price: totalPrice};

console.log(selected);
}
}

function getValue($id) {
var flower = $('#flower_price_' + $id).val();
var quantity = $('#quantity_' + $id).val();
var result = (flower * quantity);
$('#total_price_' + $id).val(result);

}


And Table



<tr>
<td><?= $value->flower_name ?></td>
<td class="text-right">
<input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="flower_price" id="flower_price_<?= $value->id ?>">
</td>
<td class="text-right">
<input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="quantity" id="quantity_<?= $value->id ?>">
</td>
<td class="text-right">
<input type="text" class="form-control" name="total_price" id="total_price_<?= $value->id ?>">
</td>
<td>
<div class="checkbox">
<label>
<input type="checkbox" onclick="customerCheckBox('<?= $value->id ?>')" name="flower_id" value="<?= $value->id ?>" id="flower_id_<?= $value->id ?>">
</label>
</div>
</td>
</tr>





share|improve this answer























    Your Answer






    StackExchange.ifUsing("editor", function () {
    StackExchange.using("externalEditor", function () {
    StackExchange.using("snippets", function () {
    StackExchange.snippets.init();
    });
    });
    }, "code-snippets");

    StackExchange.ready(function() {
    var channelOptions = {
    tags: "".split(" "),
    id: "1"
    };
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function() {
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled) {
    StackExchange.using("snippets", function() {
    createEditor();
    });
    }
    else {
    createEditor();
    }
    });

    function createEditor() {
    StackExchange.prepareEditor({
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: true,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    imageUploader: {
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    },
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    });


    }
    });














    draft saved

    draft discarded


















    StackExchange.ready(
    function () {
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456095%2fhow-to-insert-input-text-from-datatables-to-database-and-multiply-2-values-pass%23new-answer', 'question_page');
    }
    );

    Post as a guest















    Required, but never shown

























    1 Answer
    1






    active

    oldest

    votes








    1 Answer
    1






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    0














    Here is the solution



    Javascript



    function customerCheckBox($id) {
    var selected = new Array();
    var flowerPrice = $('#flower_price_' + $id).val();
    var qunatity = $('#quantity_' + $id).val();
    var totalPrice = $('#total_price_' + $id).val();
    var selected = {flower_id: $id, flower_price: flowerPrice, qunatity: qunatity,
    total_price: totalPrice};

    console.log(selected);
    }
    }

    function getValue($id) {
    var flower = $('#flower_price_' + $id).val();
    var quantity = $('#quantity_' + $id).val();
    var result = (flower * quantity);
    $('#total_price_' + $id).val(result);

    }


    And Table



    <tr>
    <td><?= $value->flower_name ?></td>
    <td class="text-right">
    <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="flower_price" id="flower_price_<?= $value->id ?>">
    </td>
    <td class="text-right">
    <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="quantity" id="quantity_<?= $value->id ?>">
    </td>
    <td class="text-right">
    <input type="text" class="form-control" name="total_price" id="total_price_<?= $value->id ?>">
    </td>
    <td>
    <div class="checkbox">
    <label>
    <input type="checkbox" onclick="customerCheckBox('<?= $value->id ?>')" name="flower_id" value="<?= $value->id ?>" id="flower_id_<?= $value->id ?>">
    </label>
    </div>
    </td>
    </tr>





    share|improve this answer




























      0














      Here is the solution



      Javascript



      function customerCheckBox($id) {
      var selected = new Array();
      var flowerPrice = $('#flower_price_' + $id).val();
      var qunatity = $('#quantity_' + $id).val();
      var totalPrice = $('#total_price_' + $id).val();
      var selected = {flower_id: $id, flower_price: flowerPrice, qunatity: qunatity,
      total_price: totalPrice};

      console.log(selected);
      }
      }

      function getValue($id) {
      var flower = $('#flower_price_' + $id).val();
      var quantity = $('#quantity_' + $id).val();
      var result = (flower * quantity);
      $('#total_price_' + $id).val(result);

      }


      And Table



      <tr>
      <td><?= $value->flower_name ?></td>
      <td class="text-right">
      <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="flower_price" id="flower_price_<?= $value->id ?>">
      </td>
      <td class="text-right">
      <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="quantity" id="quantity_<?= $value->id ?>">
      </td>
      <td class="text-right">
      <input type="text" class="form-control" name="total_price" id="total_price_<?= $value->id ?>">
      </td>
      <td>
      <div class="checkbox">
      <label>
      <input type="checkbox" onclick="customerCheckBox('<?= $value->id ?>')" name="flower_id" value="<?= $value->id ?>" id="flower_id_<?= $value->id ?>">
      </label>
      </div>
      </td>
      </tr>





      share|improve this answer


























        0












        0








        0







        Here is the solution



        Javascript



        function customerCheckBox($id) {
        var selected = new Array();
        var flowerPrice = $('#flower_price_' + $id).val();
        var qunatity = $('#quantity_' + $id).val();
        var totalPrice = $('#total_price_' + $id).val();
        var selected = {flower_id: $id, flower_price: flowerPrice, qunatity: qunatity,
        total_price: totalPrice};

        console.log(selected);
        }
        }

        function getValue($id) {
        var flower = $('#flower_price_' + $id).val();
        var quantity = $('#quantity_' + $id).val();
        var result = (flower * quantity);
        $('#total_price_' + $id).val(result);

        }


        And Table



        <tr>
        <td><?= $value->flower_name ?></td>
        <td class="text-right">
        <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="flower_price" id="flower_price_<?= $value->id ?>">
        </td>
        <td class="text-right">
        <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="quantity" id="quantity_<?= $value->id ?>">
        </td>
        <td class="text-right">
        <input type="text" class="form-control" name="total_price" id="total_price_<?= $value->id ?>">
        </td>
        <td>
        <div class="checkbox">
        <label>
        <input type="checkbox" onclick="customerCheckBox('<?= $value->id ?>')" name="flower_id" value="<?= $value->id ?>" id="flower_id_<?= $value->id ?>">
        </label>
        </div>
        </td>
        </tr>





        share|improve this answer













        Here is the solution



        Javascript



        function customerCheckBox($id) {
        var selected = new Array();
        var flowerPrice = $('#flower_price_' + $id).val();
        var qunatity = $('#quantity_' + $id).val();
        var totalPrice = $('#total_price_' + $id).val();
        var selected = {flower_id: $id, flower_price: flowerPrice, qunatity: qunatity,
        total_price: totalPrice};

        console.log(selected);
        }
        }

        function getValue($id) {
        var flower = $('#flower_price_' + $id).val();
        var quantity = $('#quantity_' + $id).val();
        var result = (flower * quantity);
        $('#total_price_' + $id).val(result);

        }


        And Table



        <tr>
        <td><?= $value->flower_name ?></td>
        <td class="text-right">
        <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="flower_price" id="flower_price_<?= $value->id ?>">
        </td>
        <td class="text-right">
        <input type="text" onblur="getValue('<?= $value->id ?>')" class="form-control" name="quantity" id="quantity_<?= $value->id ?>">
        </td>
        <td class="text-right">
        <input type="text" class="form-control" name="total_price" id="total_price_<?= $value->id ?>">
        </td>
        <td>
        <div class="checkbox">
        <label>
        <input type="checkbox" onclick="customerCheckBox('<?= $value->id ?>')" name="flower_id" value="<?= $value->id ?>" id="flower_id_<?= $value->id ?>">
        </label>
        </div>
        </td>
        </tr>






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 24 '18 at 13:19









        Gss VenkateshGss Venkatesh

        12010




        12010






























            draft saved

            draft discarded




















































            Thanks for contributing an answer to Stack Overflow!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid



            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.


            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53456095%2fhow-to-insert-input-text-from-datatables-to-database-and-multiply-2-values-pass%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            A CLEAN and SIMPLE way to add appendices to Table of Contents and bookmarks

            Calculate evaluation metrics using cross_val_predict sklearn

            Insert data from modal to MySQL (multiple modal on website)