-4

I want to send to my onClick function, the value of the mysql data that echo on function.

I have this function

<script>
function showDetails(ask) {

 <?php 
 mysql_query("DELETE FROM `registration` WHERE `registration`.`uid` = ask") or die("query not working");?>
return true;
}
</script>

//php code to send the value to showDetails() function

<?php  
     while ($user_field = mysql_fetch_assoc($userdata))    {
        $sak=$user_field['uid'];
        ?>
        <a href="edit.php?myid=<?php print $user_field['uid']; ?>">Edit</a>&nbsp;
        <a href="#" onClick="showDetails('<?php echo $sak; ?>');">Delete</a>
     <?php         
     }
?>

Not Passing value :(

4 Answers4

3

You need to add a parameter to your showDetails function like

showDetails(ask){
  alert(ask)

}

and remove the $ from the JS-Code. It's an PHP-Variable

Agreon
  • 31
  • 3
0

Add parameter to showDetails function

<script>
function showDetails(sak) {
alert(sak);
return true;
}
</script>
Shaik Matheen
  • 1,233
  • 15
  • 14
0

Try this :

<script>
function showDetails(sak) {
   var uid = sak;
   if(confirm("Are you sure delete this id "+uid)) {
      return true;
   }
}
</script>
Razib Al Mamun
  • 2,663
  • 1
  • 16
  • 24
0

Try HTML5 attribute. PHP:

<?php  
while ($user_field = mysql_fetch_assoc($userdata))  {
  $sak=$user_field['uid'];
  ?><a href="edit.php?myid=<?php print $user_field['uid']; ?>">Edit</a>&nbsp;<a href="#" id="sak-anc" data-sak="<?php echo $sak; ?>">Delete</a><?php
}
?>

JS: just make sure that you need to include jquery library to use JQuery function.

$("#sak-anc").click( function() {
        var sak = $(this).data("sak");
        alert(sak);
});

You can get more detail from here. Hope this help you well!

AddWeb Solution Pvt Ltd
  • 21,025
  • 5
  • 26
  • 57