i’am working on checkboxes when user click checkbox i am checking is it checked or not if checked i update value on database here is my code
$(document).ready(function(){
$('input[type="checkbox"]').bind('click',function()
{
var tObj = $(this).val();
if ($('#checkpermission').is(':checked'))
{
alert(tObj);
$.ajax({
url: 'checkpermission.php',
data: {"Selected":tObj},
type: 'post',
success:function(data)
{
alert(data);
//Succes!
}
});
}
else
{
// alert(tObj);
$.ajax({
url: 'uncheckpermission.php',
data: {"Selected":tObj},
type: 'post',
success:function(data)
{
alert(data);
//Succes!
}
});
}
});
});
<?php
session_start();
require 'dbconnect.php';
$page_name="RegisterUsers.php";
$start=$_GET['start'];
if(strlen($start) > 0 and !is_numeric($start))
{
echo "Data Error";
exit;
}
$eu = ($start - 0);
$limit = 8;
$this1 = $eu + $limit;
$back = $eu - $limit;
$next = $eu + $limit;
$query="select * from tbl_user where username!='admin' and password!='admin'";
$result=mysql_query($query);
$nume=mysql_num_rows($result);
if($nume>0)
{
if($_REQUEST['SearchText'])
{
$find=$_REQUEST['SearchText'];
$query="select * from tbl_user where username!='admin' and password!='admin' and username LIKE'%$find%' or Email LIKE'%$find%' or PhoneNumber LIKE'%$find%' order by id limit $eu, $limit";
}
else
{
$query="select * from tbl_user where username!='admin' and password!='admin' order by username limit $eu, $limit";
}
$result=mysql_query($query);
while($data=mysql_fetch_row($result))
{
if($data[5])
{
$path=$redirect."/services/User/".$data[5];
}
else
{
$path=$redirect."/images/noimage.png";
}
?>
<tr>
<td class="gallery">
<a href='<?=$path ?>'>
<img width="50" height="50" src=<?php echo $path; ?> />
</a>
</td>
<!--<td id='myText'><img width=50 height=50 src=<?php echo $path; ?> /></a></td>-->
<td><?=$data[1]?></td>
<td><?=$data[3]?></td>
<td><?=$data[4]?></td>
<td>
<div style="padding-left:25px;">
<INPUT TYPE="checkbox" class="checkpermission" name="checkuser" id="checkpermission" value='<?=$data[0]?>'<?php if($data[6]=="Read-Write"){echo "checked";}?>>
</div>
<div>
Read-Write
</div>
</td>
<td class='delete'><a href='http://ifliptips.com/admin/VueGuides/AddUser.php?id=<?=$data[0]?>&action=edit' >Edit</a></td>
<td class='delete'><a href='http://ifliptips.com/admin/VueGuides/RegisterUsers.php?id=<?=$data[0]?>&action=delete' onClick="return deletepressed();">Delete</a></td>
</tr>
<?php
}
}
?>
every time when user click goes on if condition only else loop not working i am seeing response
so can any one guide me how can i overcome this
Thanks for advance.
Try to use
Solution
There were more than one check box with
checkpermission. So the code needs to be modified like thisAjay will change the code to generate unique ids for the checkbox. Above code will work for this case too.
Check this jsFiddle
Hope this works for you.