Deepak Awashti

Deepak Awashti

  • NA
  • 301
  • 74.5k

how to create dynamic checkbox using jquery

Dec 15 2015 4:47 AM
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" />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input type="button" id="btnsum" value="Calculate" />
<table id="tblGnrate"></table>
 
 
----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- 
 
 
please provide textbox and checkbox code and sum value only checked textbox  
 

Answers (8)