Skip to content

Instantly share code, notes, and snippets.

@mazfreelance
Last active August 24, 2017 03:48
Show Gist options
  • Save mazfreelance/c0ee64d3d414d12bd57d65f3843da44c to your computer and use it in GitHub Desktop.
Save mazfreelance/c0ee64d3d414d12bd57d65f3843da44c to your computer and use it in GitHub Desktop.
JQUERY: Check & Uncheck using selection with database
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<SCRIPT language="javascript">
$(document).ready(function() {
//delete
$("#deletemessage").click(function() {
});
//check in database
var str = '<td class="bodyBorder"><input type="checkbox" name="deletemsg[]" id="deletemsg" value="<?php echo $dtlMessage['msg_id']?>"/></td>';
$(".trbody").append(str);
// check delete message
$("#check").change(function() {
var d = $(this).val();
//alert(d);
if(d == 'parent'){
$(".trbody #deletemsg").prop("checked", !d.checked);
}
});
// uncheck delete message
$("#check").change(function() {
var d = $(this).val();
if(d == 'parentnone'){
$(".trbody #deletemsg").prop("checked", false);
}
});
});
</SCRIPT>
<!-- Interface -->
<div align="right" style="margin-right:15%;">
<select id="check">
<option selected disabled="">&nbsp;</option>
<option value="parent" data-checked='false'>All</option>
<option value="parentnone" data-checked='false'>None</option>
</select>
<button id="deletemessage" style="background:purple;border: 1px solid #fff" title="Delete Message"><i class="fa fa-trash-o" aria-hidden="true" style="font-size: 1em;color:#fff;"></i></button>
</div>
<table id="content02" class=" postTable">
<center>
<th width="5%"></th>
<th class="headColor" width="15%">Date</th>
<th class="headColor">Message</th>
<th class="headColor" width="8%">Action</th>
<?php
//Print the contents
$i = $start;
foreach ($result as $dtlMessage){
$i++;
$class = 'even';
if (($i % 2) == 1) {
$class='odd' ;
}
$msg = str_replace('break','<br />',$dtlMessage['msgText']);
?>
<tr class="trbody">
<td class="bodyBorder"><?php echo $i?>&nbsp;</td>
<td class="bodyColor" align="center" style="cursor:pointer;" id="<?php echo $dtlMessage['msg_id']?>">
<?php
if($dtlMessage['msgsts']=="new"){
echo '<strong>'.date("d-m-Y", strtotime($dtlMessage['msgDt'])).'</strong>';
}
else{
echo date("d-m-Y", strtotime($dtlMessage['msgDt']));
}
?>
</td>
<td class="bodyColor" style="cursor:pointer;" id="<?php echo $dtlMessage['msg_id']?>">
<?php
if($dtlMessage['msgsts']=="new"){
echo '<strong>'.substr($msg,0,29).'...</strong>';
}
else{
echo substr($msg,0,29).'...';
}
?>
</td>
<!--
<td>delete message</td>
-->
</tr>
<?php
}
?>
</center>
</table>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment