checkbox checked table data selectd
<div class="col-sm-4 form-group">
<label class="mt-checkbox">
<input type="checkbox" name="all_donor" value="1" onclick="alldonar();"> All Donor
<span></span>
</label>
</div>
<!-- all_donar_Modal -->
<div class="modal fade" id="all_donar_Modal" tabindex="-1" role="dialog" aria-labelledby="exampleModalCenterTitle"
aria-hidden="true">
<div class="modal-dialog modal-dialog-centered" role="document">
<div class="modal-content">
<div class="modal-header">
<h5 class="modal-title" id="exampleModalCenterTitle">List of All Donar</h5>
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<span aria-hidden="true">×</span>
</button>
</div>
<div class="modal-body" style="height:300px;padding: 20px;overflow: auto;">
<div class="col-md-8">
<div class="table-responsive">
<table class="table">
<thead>
<tr>
<th scope="col">
<input type="checkbox" class="selectall">
</th>
<th scope="col">Name</th>
<th scope="col">Mobile</th>
</tr>
</thead>
<tbody id="all_donar_data_show">
</tbody>
</table>
</div>
</div>
<div class="col-md-4">
<div class="mt-radio-inline">
<label class="control-label">Type Message Here - <span class="text-danger"
id="message_count">0</span> Character Type (MAX: 160 Characters)</label><br />
<textarea name="donor_message" class="alldonarformessage" id="donor_message" rows="8"
maxlength="160" style="width: 100%;color: #000;" required></textarea>
</div>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">Close</button>
<button type="button" class="btn btn-primary" onclick="sendMessge_all_donar_Modal()">Send
Message</button>
</div>
</div>
</div>
</div>
<!-- //retrive data -->
<?php
function get_data_all_donar(){
$data = $this->Crud_model->get_table_by_table_name('donor');
echo json_encode($data);
}
// sendMessgeTodaysBirthday
function sendMessgeAllDonar(){
$value=$_POST['messageValue'];
$alldonardata = json_decode($value,TRUE);
foreach($alldonardata as $key=>$val) {
$mobile= $val['mobile'];
$message= $val['message'];
if (strlen($mobile)==11) {
$result = $this->send_sms($mobile, $message);
}
if($result=='ok') {
$success = true;
$this->ModelExtra->setMessageList('Success', $donor->id);
} else {
$this->ModelExtra->setMessageList('Failed', $donor->id);
}
}
}
?>
<script>
//select all
$('.selectall').click(function() {
if ($(this).is(':checked')) {
$('input:checkbox').attr('checked', true);
} else {
$('input:checkbox').attr('checked', false);
}
});
//today's birthday
function alldonar() {
var html = '';
jQuery.ajax({
type: "POST",
url: "<?php echo base_url('message/get_data_all_donar');?>",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(data) {
console.log(data);
for (var i = 0; i < data.length; i++) {
html += `
<tr>
<td scope="col">
<input type="checkbox" name="donarid[]" id="donarid" value="${data[i].id}">
</td>
<td>${data[i].name}</td>
<td>${data[i].phone_no}</td>
</tr>
`;
}
$("#all_donar_data_show").html(html);
html = '';
},
failure: function(response) {
alert(response.d);
}
});
$('#all_donar_Modal').modal('show');
}
// sendMessge_all_donar_Modal
function sendMessge_all_donar_Modal() {
var donorformessage = $('.alldonarformessage').val();
var grid = document.getElementById("all_donar_data_show");
//Reference the CheckBoxes in Table.
var checkBoxes = grid.getElementsByTagName("input");
var message = "";
// console.log(checkBoxes);
var values = new Array();
for (var i = 0; i < checkBoxes.length; i++) {
if (checkBoxes[i].checked) {
var row = checkBoxes[i].parentNode.parentNode;
message += row.cells[1].innerHTML;
message += " " + row.cells[2].innerHTML;
values.push({
'name': row.cells[1].innerHTML,
'mobile': row.cells[2].innerHTML,
'message': donorformessage
});
}
}
var DataJSONString = JSON.stringify(values);
$.ajax({
type: "POST",
url: "<?php echo base_url('message/sendMessgeAllDonar');?>",
data: {
messageValue: DataJSONString
},
success: function(res) {
$('#all_donar_Modal').modal('hide');
}
});
}
</script>
Comments
Post a Comment