Jump to content

Dynamic calculator


FooKelvin

Recommended Posts

Hi Guys,

 

I have a dynamic input field, consists of requirement details.

Each input field have their own sub amount.

 

at the end, the total will sum all the sub amount.

But i have stuck, i do not know how to count the amount, since it's dynamic, how can i get the dynamic id and count it as sub total or grand total?

 

Please refer to my codes above:

 

javascript:

$(document).ready(function () {
    var max_fields = 10; //maximum input boxes allowed
    var wrapper = $(".input_fields_wrap"); //Fields wrapper
    var add_button = $(".add_field_button"); //Add button ID
                        
    var x = 1; //initlal text box count
    $(add_button).click(function (e) { //on add input button click
        e.preventDefault();
        if (max_fields > x) { //max input box allowed
            x++; //text box increment
            $(wrapper).append('<div><table><tr><td style="width:272px">Notice Period - '+x+'</td><td style="width: 14%;"><input name="txt_pe_start[]" type="text" value="" class="input_class start" style="width: 100px; vertical-align: top;"/></td><td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Consists of <input name="consits[]" value="" style="width: 25px;">Day(s)</input></td><td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Short Notice <input name="shortNotice[]" class="sndays" id="sndays_'+x+'" value="" style="width: 25px;">Day(s)</input></td><td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Amount Due<input id="amountdue_'+x+'" name="amountdue[]" style="width: 100px;"></input></td></tr></table></div>'); //add input box
        }
    });// JavaScript source code

html:

<div class="input_fields_wrap">
 <div>
<table>
<tr>
<td style="width:272px">Notice Period - 1</td>
<td style="width: 14%;"><input name="txt_pe_start[]" type="text" value="" class="input_class start" style="width: 100px; vertical-align: top;"/></td>
<td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Consists of <input name="consits[]" style="width: 25px;">Day(s)</input></td>
<td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Short Notice
<input name="shortNotice[]" class="sndays" id="sndays_1" style="width: 25px;">Day(s)</input>
</td>
<td style="width: 165px;display: inline;padding: 0 5px 0 5px;">Amount Due<input id="amountdue_1" name="amountdue[]" style="width: 100px;"></input></td>
</tr>
</table>
</div>
</div>
<button class="add_field_button">Add More Fields</button>
Total:<div></div>
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.