I have an issue where I can't reflect the total amount of value in specific item, I tried putting an ID and call it whenever it will onCHange
the input fields and it didn't reflect at all, is there any problem/lacking? , and also I want to remove the specific item in each row if the button clicked the remove item, is there any wrong with the current code?
$("#allcb").change(function () {
$('tbody tr td input[type="checkbox"]').prop(
"checked",
$(this).prop("checked")
);
});
$(document).on( "keyup", ".quantity_input",function() {
var value_input = $(".quantity_input").val();
var price_value = $(".price_value").html();
var total_value = parseInt(value_input) * parseInt(price_value);
$(".total_value_row").text(total_value);
});
$(document).on("click",".remove_data" , function(){
alert("I've been clicked! remove the row item");
});
$(document).ready(function () {
$("#add_data").click(function () {
var grid = document.getElementById("Table1");
var message = "Values Description\n";
var checkBoxes = grid.getElementsByTagName("INPUT");
var str = ''
for (var i = 0; i < checkBoxes.length; i++) {
if (
checkBoxes[i].checked &&
checkBoxes[i].name !== "allcb" &&
!checkBoxes[i].hasCovered
) {
var row = checkBoxes[i].parentNode.parentNode;
str +=
'<div class="row" ><div class="col-md-8"><p class="me-3"> ' +
'<a href="#" class="text-body">' +
'<button type="button" class = "remove_data" id="remove_data">Remove item</button></a> ' +
'<span>Quantity</span> ' +
row.cells[2].innerHTML +
"</a></p> " +
'<span class="me-1">Price </span> ' +
'<span class="me-1 price_value">' +
row.cells[1].innerHTML +
"</span> " +
'<input type="number" id="quantity_input" class="form-control form-control-sm w-px-75 quantity_input" value="1" min="1" max="5"/> '+
'<span class= "total_value_row" >total value is</span> '+
"</div></div><hr>";
checkBoxes[i].hasCovered = true;
}
}
$(".whole-div-class").append(str);
});
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script>
<table border="1" id="Table1">
<thead>
<tr>
<th>
<input type="checkbox" id="allcb" name="allcb" />
</th>
<th>Price</th>
<td>Quantity</td>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="checkbox" id="cb1" name="cb1" />
</td>
<td>200</td>
<td> 25</td>
</tr>
<tr>
<td>
<input type="checkbox" id="cb2" name="cb2" />
</td>
<td>300</td>
<td>30</td>
</tr>
<tr>
<td>
<input type="checkbox" id="cb3" name="cb3" />
</td>
<td>400</td>
<td>50</td>
</tr>
</tbody>
</table>
<br />
<button type="button" id="add_data">Add data</button>
<hr>
<div class="row whole-div-class"></div>