I have developed two tables "TABLE1" and "TABLE2". I want if i enter subject name in Table 1 then it will automatically copy in Table 2 and if click on "Add new+" button of Table1 to add new row then this change will happen on Table2.
$("#insert66").click(function () {
$("#table66").each(function () {
var tds = '<tr>';
jQuery.each($('tr:last td', this), function () {
tds += '<td>' + $(this).html() + '</td>';
});
tds += '</tr>';
if ($('tbody', this).length > 0) {
$('tbody', this).append(tds);
} else {
$(this).append(tds);
}
});
});
Table1:-
<table id="table66" class="table table-bordered table-hover">
<input type="button" class="btn green" value="Add New+" id="insert66"></input>
<thead>
<th>Subject Name</th>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="form-control subName" name="subName">
</td>
</tr>
</tbody>
</table>
Table2:-
<table id="tablecourse" class="table table-striped table-hover">
<thead>
<tr>
<th>Subject Name</th>
<th>Campus</th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="text" class="form-control subName" name="subName">
</td>
<td>
<select id="multipleSelectExample4" style="width:100%;" data-placeholder="Select an option">
<option value="1">Option 1</option>
<option value="2">Option 2</option>
<option value="3">Option 3</option>
<option value="4">Option 4</option>
<option value="5">Option 5</option>
</select>
</td>
</tr>
</tbody>
</table>
I have found one logic but bit clueless how to use this
var counterClass = 0
$("#table66 input").change(function(){
if($(this).hasClass("completed")) {
// update
$("." + $(this).attr("refClass")).html($(this).val())
} else {
// append/insert
$(this).addClass("completed").attr("refClass", "refClass" + counterClass)
counterClass += 1
$().append()
}
})