I have echo PHP table with 3 tds: 1- checkbox. 2- names. 3- phone Numbers
I made textarea to contain all checked checkboxes tds phone Numbers into it.
I tried to modificate this code but it doesn't work with me.
My code :
<table class="table table-striped table-bordered TableStyle" id="table-scroll ">
<thead>
<th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
<th class="thead">Name</th>
<th class="thead">Phone</th>
</thead>
<tbody>
<tr>
<td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
<td>AMMAR</td>
<td>123456789</td>
</tr>
<tr>
<td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
<td>Sara</td>
<td>987654321</td>
</tr>
</tbody>
</table>
<button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>
<textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>
A possible solution is to use jQuery.
Maybe this example can get you started. When you click the 'Add' button, the phonenumbers will be added to the textarea.
$(document).ready(function() {
$('#confirmNums').click(function() {
var newline = "
";
var sendToNum = $('#sendToNum');
sendToNum.text('');
$("input[name=check]:checked").each(function() {
var phoneNumber = $(this).parent().nextAll('td').eq(1).html();
sendToNum.append(phoneNumber + newline);
});
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<table class="table table-striped table-bordered TableStyle" id="table-scroll ">
<thead>
<th class="thead"><input type="checkbox" name="checkallnum" value="" id="checkallnum2" /></th>
<th class="thead">Name</th>
<th class="thead">Phone</th>
</thead>
<tbody>
<tr>
<td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
<td>AMMAR</td>
<td>123456789</td>
</tr>
<tr>
<td><input class="checkBoxClass" type="checkbox" name="check" value="" /></td>
<td>Sara</td>
<td>987654321</td>
</tr>
</tbody>
</table>
<button type="button" id="confirmNums" class="btn btn-primary pull-left" style="">Add</button>
<textarea rows="8" name="" id="sendToNum" class="form-control" style="margin-bottom: 10px;" tabindex="1"></textarea>
</div>