Hello everyone, I am a new member of this forum and I am looking forward to learning and contributing with all of you. I have encountered a problem that I tried to solve on my own but couldn't figure it out. Would anyone be able to lend me a hand? Here is the code snippet I am working on: Jquery:
$(document).ready(function() {
var max_fields = 10; allowed
var moreprod = $(".contenedor"); wrapper
var add_button = $("#e");
var x = 1;
$(add_button).click(function(e){
e.preventDefault();
if(x < max_fields){
x++; //text box increment
$(moreprod).append('<div class="fieldprod"><div id="a"><input type="text" placeholder="Product"></input></div><div id="b" class="csymbol" data-symbol="$"><input id="prices" type="text" placeholder=" 0.00"></input></div><div id="c"><input id="prices" type="text" placeholder="qty"></input></div><div id="d" class="csymbol" data-symbol="$"><p id="qty">0.00</p></div><div id="f" class="removebtn">-</div></div>'); //add input box
}
});
$(moreprod).on("click",".removebtn", function(e){
e.preventDefault(); $(this).parent('div').remove(); x--;
})
});
HTML:
<div class="result">total</div>
<div class="contenedor">
<div class="fieldprod">
<div id="a">
<input type="text" placeholder="Product"></input>
</div>
<div id="b" class="csymbol" data-symbol="$">
<input id="prices" type="text" placeholder=" 0.00"></input>
</div>
<div id="c">
<input id="prices" type="text" placeholder="qty"></input>
</div>
<div id="d" class="csymbol" data-symbol="$"><p id="qty">0.00</p></div>
<div id="e">+</div>
</div>
</div>
I am dynamically creating three inputs and two divs to form a row. However, I need help in summing up the values from two inputs (c = a + b) within each row.
If I add a new row, I want to make the sum of values in that row (g = e + f), and then calculate the total sum (total = c + g).
Can anyone assist me with this task?
Thank you in advance for your help, and I apologize for any language errors in my message.