Click here to Skip to main content
15,886,422 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
how to create dynamic checkbox using jquery
1. Generate .....

Textbox generate then attach checkbox in all generated textbox

2. Calculation...

Total 6 textbox and chk box generated and fill the value in all textbox but checkbox check only 3 textbox then sum button click calculate only checked textbox value and display in total ...


please help me ....


my textbox generated code and Calculate value using without Checkbox ..

--------------------------------Code----------------------------------------

<script>
$(document).ready(function ()
{
$("#btnshow").click(function ()
{
var rows = $("#txtRows").val();
var columns = $("#txtColumns").val();
var htmlData = "";
for (var i = 0; i < rows; i++)
{
//var $ctr = $('<input/>').attr({ type: 'checkbox', name: 'chk' }).addClass("chk");
//$("#tblGnrate").append($ctrl);
htmlData += "<tr>";
for (var j = 0; j < columns; j++)
{
htmlData += "<td><input type='text' name='txtValue' id='txtBox" + i + "" + j + "' /></td>"
}
htmlData += "</tr>";
}
$("#tblGnrate").html(htmlData);
});
// sum all the text box values
var Total = 0;
$("#btnsum").click(function ()
{
$('#tblGnrate').each(function (i, row)
{
var $row = $(row), $txtbox = $row.find('input[name="txtValue"]');
$txtbox.each(function (i, txtbox)
{
var $t = $(txtbox);
Total = Total + parseInt($t.val(),10);
});
});
alert(Total);
Total = 0;
});
});
</script>
</head>
<body>
Rows:<input type="text" id="txtRows" />
Columns:<input type="text" id="txtColumns" /><br /><br /><br />
<input type="button" id="btnshow" value="Generate" />      
<input type="button" id="btnsum" value="Calculate" />
<table id="tblGnrate"></table>

-------------------------------------------------


please provide textbox and checkbox code and sum value only checked textbox
Posted
Updated 14-Dec-15 23:01pm
v3
Comments
Amit Jadli 15-Dec-15 5:29am    
What error you are getting?? or where you got stuck??
ZurdoDev 15-Dec-15 7:27am    
What is your question?

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900