Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
58
rated 0 times [  65] [ 7]  / answers: 1 / hits: 20124  / 14 Years ago, fri, october 29, 2010, 12:00:00



i want to pass my php variable in one javascript function.

i know it seems simple but i don't know where am i missing something?



    <?php
while($gg=mysql_fetch_array($lg))
{
?>
<td id=add_td>
<?php
$id = $gg['p_id'];
echo <a onclick=cnf('Are you sure you want to delete that?',$id)>; ?>Delete</a>
</td>
<?php
}
?>


and in my javascript function



function cnf(msg,id)
{

cnf = confirm(msg);
if(cnf) {
parent.location.href = 'p_update.php?d=' + id;
}
}


so i need to know on which id that user had clicked so that i will only delete that id from database.

if i try this thing then it showing error on cnf function and its saying like unterminated string literal?


More From » php

 Answers
152
if $id is not numeric you should write 

<?php
while($gg=mysql_fetch_array($lg))
{
?>
<td id=add_td>
<?php
$id = $gg['p_id'];
echo <a onclick=cnf('Are you sure you want to delete that?','.$id.')>; ?>Delete</a>
</td>
<?php
}
?>

[#95142] Tuesday, October 26, 2010, 14 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
cristopherh

Total Points: 402
Total Questions: 117
Total Answers: 84

Location: Monaco
Member since Fri, Sep 24, 2021
3 Years ago
;