Click here to Skip to main content
15,886,963 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have 2 textboxes and through that i want to add that value to the column of the table once I clicked on Save button.

problem: I have done that but problem is when I added second row in the table then first row values gets replaced with second row value as well.

here is my code,

Kindly help me .. Thanks in Advance.

HTML
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

  <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  <script src="//code.jquery.com/ui/1.10.4/jquery-ui.js"></script> 
 <style>
 table,tr,td
 {
	border:1px solid red;
 }
 </style>
<script>
$(document).ready(function(){
$("#btn").click(function(){

var a1=$("#txt_Name").val();
var b1=$("#txt_Salary").val();
$(".spanFname").text(a1);
$(".spanSal").text(b1);
 
var test=$("#testDiv").html();

$("#tbl").append(test);




});

});
</script>  

</head>

<body>
<div>
<table id="tbl">
<tr>
<td>
<input type="checkbox" name="selectAll" value="All"><br>
</td>
<td>Name</td>
<td>Salary</td>
<td>Buttuons</td>
</tr>
</table>
</div>


<div>
<br/>
<label>Name: </label>
<input type="textbox" id="txt_Name"/>
<br/>
<label>Salary: </label>
<input type="textbox" id="txt_Salary"/>
<br/>
<input type="button" id="btn" value="Add Row"/>
</div>

<div style="display:none;" id="testDiv">
<tr id="testTr">
<td><input type="checkbox" name="selectAll" value="All"></td>
<td><span class="spanFname"></span></td>
<td><span class="spanSal"></span> </td>
<td><input type="button" value="Edit"></td>
</tr>
</div>
<br/><br/>

</body>
</html>
Posted
Updated 19-Jun-14 1:21am
v2

Try this :)
JavaScript
$('#YourTableId tbody').append(
                    '<table><tbody><tr><td>' + name +
                    '</td><td>' + salary +
                    '</td></tr></tbody></table>');
 
Share this answer
 
This may help you...
JavaScript
$("#tbl").append(
               "<table><tbody><tr><td><input type='checkbox' name='selectAll' value='All'></td>"+
               "<td>"+$("#txt_Name").val()+"</td>"+
               "<td>"+$("#txt_Salary").val()+"</td>"+
               "<td><input type="button" value="Edit"></input></td></tr></tbody></table>");
 
Share this answer
 

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