noclist Posted November 17, 2010 Share Posted November 17, 2010 I'm trying to have a javascript confirm box pop up and confirm the intention to delete a record in a database. I think I'm having trouble calling the function within my PHP code, but not sure what exactly is wrong. The status bar shows something like "javascript:checkDelete(100, Title)" when I hover over the link and that seems right but nothing occurs when I click on it. Here is my code: Javascript <script language="Javascript"> function checkDelete(b,Title){ var del=confirm("Are you sure you want to delete " + Title + " from the Database?"); if (del){ document.location="delete.php?mID=" + b + "&Title=" + Title; } } </script> PHP echo "<td><a href='Javascript:checkDelete(" . $row['mID'] . "," . $row['Title'] . ")'>"; echo "<img border=0 src='images/delete.gif'>" . "</a></td></tr>"; Anyone see my error? Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/ Share on other sites More sharing options...
trq Posted November 17, 2010 Share Posted November 17, 2010 Title needs quotes around it... echo "<td><a href='Javascript:checkDelete(" . $row['mID'] . ",'" . $row['Title'] . "')'>"; Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135282 Share on other sites More sharing options...
noclist Posted November 17, 2010 Author Share Posted November 17, 2010 I actually tried that earlier and it does the same thing and the statusbar shows "javascript:checkDelete(100, " without the title or closing parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135285 Share on other sites More sharing options...
jcbones Posted November 17, 2010 Share Posted November 17, 2010 No need for a function here, unless you just want it. echo "<td><a href=\"delete.php?mID={$row['mID']}&Title={$row['Title']}\" onclick=\"return confirm('Are you sure you want to delete {$row['Title']} from the Database?')\">"; echo "<img border=0 src='images/delete.gif'>" . "</a></td></tr>"; Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135286 Share on other sites More sharing options...
noclist Posted November 17, 2010 Author Share Posted November 17, 2010 Cool that worked, not sure why I couldn't get the function to pop up though. Thanks for the help. Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135309 Share on other sites More sharing options...
jcbones Posted November 17, 2010 Share Posted November 17, 2010 The function wouldn't work because you double nested it with single quotes. <a href='Javascript:checkDelete(234,'Title');'> Will not work as the single quote in the javascript function would close the href in the html element. To fix this, you would have to write your php echo statement with double quotes. echo "<td><a href=\"Javascript:checkDelete(" . $row['mID'] . ",'" . $row['Title'] . "')\">"; Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135317 Share on other sites More sharing options...
noclist Posted November 17, 2010 Author Share Posted November 17, 2010 Got it, thank you. Quote Link to comment https://forums.phpfreaks.com/topic/218908-javascriptphp-help/#findComment-1135668 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.