Hi, I have created a dynamic table using jquery. and this table is nested table.
But the problem is, when i want to add rows dynamically first row is created smoothly but after that row , all rows are created under that last row. where the nested table is
my code is attached here
----------------
But the problem is, when i want to add rows dynamically first row is created smoothly but after that row , all rows are created under that last row. where the nested table is
my code is attached here
----------------
Code:
<!DOCTYPE html>
<head>
<title>Beneficiary Change Form</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script>
function AddRow() {
document.getElementById("dataTable").insertRow(1).innerHTML = '<td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td>';
}
function RemoveRow() {
document.getElementById("dataTable").remove(1).innerHTML = '<td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td>';
}
function AddTableRow() {
$("#dataTable").last().after("<tr><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td><td><input type=text></input></td></tr>");
}
</script>
</head>
<body style='text-align: center'>
<input type='file' style='display: none;' id='inputfile' /><br />
<form name='BNFChangeForm' id='BNFChangeForm' method='POST' action=''>
<table style="text-align: center; width: 75%; padding-left: 150px;" border="0" id="">
<tr>
<td style="text-align: center; font-size: x-large">Beneficiary Change Form
<hr />
</td>
</tr>
<tr>
<td style="text-align: center">
<b>Member Account Number : </b>9999999999 aaaaaaaaaa
</td>
</tr>
<tr>
<td style="text-align: left">
<b>Select Share ID </b>
<select style="width: 100px">
<option>01</option>
<option>02</option>
<option>03</option>
<option>04</option>
<option>05</option>
</select>
<input type="submit" onclick="" id="BtnRefresh" value="Refresh" />
</td>
</tr>
<tr>
<td style="text-align: left">
<br>
<p style='font-size: large; font-weight: bold; text-align: left;'>
Please review the updated beneficiary information below and sign in the space provided. If there are changes,
please note the correction and return the form to an Alliant Member Service Representative for processing.
</p>
</td>
</tr>
</table>
<div class="">
<div class="" id="chartRow;">
<!-- <div style="text-align:right;width:90%">
<a href="javascript:void(0);" id='anc_add'>Add Row</a> <a href="javascript:void(0);" id='anc_rem'>Remove Row</a><br>
</div>-->
<br>
<table width="90%" id="dataTable" border="1">
<tr>
<td style="text-align: center; vertical-align: top">A</td>
<td style="text-align: center; vertical-align: top">M</td>
<td style="text-align: center; vertical-align: top">D</td>
<td style="text-align: center; vertical-align: top">Beneficiary Name</td>
<td style="text-align: center; vertical-align: top">Address</td>
<td style="text-align: center; vertical-align: top">SSN</td>
<td style="text-align: center; vertical-align: top">DOB</td>
<td style="text-align: center; vertical-align: top">%</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" checked="checked" /></td>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" /></td>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" /></td>
<td style="text-align: center; vertical-align: top">Bill Hampe</td>
<td style="text-align: center; vertical-align: top">12345 W. Carmichael Blvd.Rancho Cucamonga, CA 12345-6654</td>
<td style="text-align: center; vertical-align: top">xxx-xx-1234</td>
<td style="text-align: center; vertical-align: top">12/12/2014</td>
<td style="text-align: center; vertical-align: top">50%</td>
</tr>
<tr>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" /></td>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" checked="checked" /></td>
<td style="text-align: center; vertical-align: top">
<input type="checkbox" /></td>
<td style="text-align: center; vertical-align: top">Sandhya Gowravajhala</td>
<td style="text-align: center; vertical-align: top">Trump Tower 2345 Northwestern Ave, Unit 213 Chicago, IL 60666-0945</td>
<td style="text-align: center; vertical-align: top">xxx-xx-1234</td>
<td style="text-align: center; vertical-align: top">12/12/2014</td>
<td style="text-align: center; vertical-align: top">50%</td>
</tr>
</table>
</div>
</div>
<div>
<table width="90%" border="0" id="Table1">
<tr>
<td style="text-align: right; padding-right: 0px" colspan="8">Total:
<input type="text" readonly="readonly" value="100%" style='border-style: none' />
</td>
</tr>
</table>
</div>
<div style="text-align: right; width: 90%">
<input type="submit" onclick="" id="ButtonSubmit" value="Submit" />
<input type="button" onclick="javascript: void (0);" id="anc_add" value="Add Row" />
<input type="button" onclick="javascript: void (0);" id="anc_rem" value="Remove Row" />
<!--<a href="javascript:void(0);" id='anc_add1'>Add Row</a> <a href="javascript:void(0);" id='anc_rem1'>Remove Row</a>-->
<br>
</div>
<!-- <table align='center' style='width: 75%'>
<tr>
<td align='center'>
<input id='btnValidate' type='submit' value='Validate' disabled='disabled' onclick='SetValidFlg(03)' />
<input id='btnSubmit' type='submit' value='Submit' onclick='SetValidFlg(01)' />
<input id='btnCancel' type='submit' value='Cancel' onclick='SetValidFlg(02)' />
</td>
</tr>
</table>-->
<script>
$(document).ready(function () {
$(document).ready(function () {
var cnt = 2;
$("#anc_add").click(function () {
$('#dataTable tr').last().after("<tr><td style=\"WIDTH: 2%;text-align:center\"><input type='checkbox' id='checkboxAdd' value='Add'/></td>" +
"<td style=\"WIDTH: 2%\;text-align:center\"><input type='checkbox' id='CheckBoxModify' value='Modify'/></td>" +
"<td style=\"WIDTH: 2%;text-align:center\"><input type='checkbox' id='CheckDelete' value='Delete'/></td>" +
"<td style=\"WIDTH: 300px\"><input type=text id='TextBeneficiaryName' style=\"WIDTH: 300px\" ></input></td>" +
"<td style=\"WIDTH: 300px\"><table id='"+cnt+"' border=0>" +
"<tr><td style=\"rowspan='2';vertical-align:top\">Add</td><td ><input type='text'><br><input type='text'></td></tr>" +
"<tr><td>City</td><td><input type='text'></td><td>St</td><td><input type='text'></td></tr>" +
"<tr><td>Zip</td><td><input type='text'></td><td>country</td><td><input type='text'></td></tr>" +
"</table></td>" +
"<td style=\"WIDTH: 100px\"><input type=text id='TextSSN' style=\"WIDTH:100px\"></input></td>" +
"<td style=\"WIDTH: 100px\"><input type=text id='TextDob' style=\"WIDTH: 100px\"></input></td>" +
"<td style=\"WIDTH: 100px\"><input type=text id='TextPercentage' style=\"WIDTH: 100px\" class = \"numeric\"></input></td></tr>");
//var x = 'Table"+cnt+"';
//alert(x);
cnt++;
});
$("#anc_rem").click(function () {
if ($('#dataTable tr').size() > 1) {
$('#dataTable tr:last-child').remove();
} else {
alert('One row should be present in table');
}
});
});
});
var specialKeys = new Array();
specialKeys.push(8); //Backspace
$(function () {
$(".numeric").bind("keypress", function (e) {
var keyCode = e.which ? e.which : e.keyCode;
var ret = ((keyCode >= 48 && keyCode <= 57) || specialKeys.indexOf(keyCode) != -1);
$(".error").css("display", ret ? "none" : "inline");
return ret;
});
$(".numeric").bind("paste", function (e) {
return false;
});
$(".numeric").bind("drop", function (e) {
return false;
});
});
</script>
</form>
</body>
</!>
Comment