"Dynamic Table row creation and Deletion"
Bootstrap 3.0.3 Snippet by indigoignition

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
<link href="//netdna.bootstrapcdn.com/bootstrap/3.0.3/css/bootstrap.min.css" rel="stylesheet" id="bootstrap-css">
<script src="//netdna.bootstrapcdn.com/bootstrap/3.0.3/js/bootstrap.min.js"></script>
<script src="//code.jquery.com/jquery-1.11.1.min.js"></script>
<!------ Include the above in your HEAD tag ---------->
<div class="container">
<div class="row clearfix">
<div class="col-md-12 column">
<table class="table table-bordered table-hover" id="tab_logic">
<thead>
<tr >
<th class="text-center">
Image Preivew
</th>
<th class="text-center">
Type of Emotion
</th>
<th class="text-center">
Source
</th>
</tr>
</thead>
<tbody>
<tr id='addr0'>
<td align = "center">
<img src = "http://www.placehold.it/200x200" alt= "..."></img>
</td>
<td>
<input type="text" name='emotion0' placeholder='emotion' class="form-control"/>
</td>
<td>
<input type="text" name='source0' placeholder='source' class="form-control"/>
</td>
</tr>
<tr id='addr1'></tr>
</tbody>
</table>
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
$(document).ready(function(){
var i=1;
$("#add_row").click(function(){
$('#addr'+i).html("<td align = 'center'><img src = 'http://www.placehold.it/200x200' alt = '...'></img></td><td><input name='emotion"+i+"' type='text' placeholder='Emotion' class='form-control input-md'/> </td><td><input name='source"+i+"' type='text' placeholder='Source' class='form-control input-md'></td>");
$('#tab_logic').append('<tr id="addr'+(i+1)+'"></tr>');
i++;
});
$("#delete_row").click(function(){
if(i>1){
$("#addr"+(i-1)).html('');
i--;
}
});
});
XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX

Related: See More


Questions / Comments:

how to add selectbox

vijay () - 7 years ago - Reply 0