webdeveloper123 Posted April 25, 2022 Share Posted April 25, 2022 Hey, sorry guys I know this is a easy one but I've been at it all day and can't seem to figure it out. I want to include this: onclick="return confirm('Are you sure?')" Inside this line of code: <td> <?php echo("<a href='delete.php?user_id=" . $d_row["FormId"] . "'>Delete</a>"); ?></td> I am deleting a record, I have all the SQL, it's all fine, but just this annoying little problem. I have tried many things , including escaping the double quotes but I have got no where. I have tried the following but none of them work: <td> <?php echo("<a href='delete.php?user_id=" . $d_row["FormId"] . "' onclick="return confirm('Are you sure?')">Delete</a>"); ?></td> <td> <?php echo("<a href='delete.php?user_id=" . $d_row["FormId"] . "onclick=\"return confirm('Are you sure?')\"'>Delete</a>"); ?></td> <td> <?php echo("<a href='delete.php?user_id=" . $d_row["FormId"] . " \"onclick=\"return confirm('Are you sure?')\"'>Delete</a>"); ?></td> Thanks Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/ Share on other sites More sharing options...
ginerjm Posted April 25, 2022 Share Posted April 25, 2022 So - what IS happening? Are you getting an error message? Or does the JS never show up? Here is what I converted it to: $formid = $d_row['FormId']; echo "<td><a href='delete.php?user_id=$formid' onclick=\"return confirm('Are you sure?')\">Delete</a></td>"; Couldn't make it work with the reference to the array element so I moved it to a simple variable. Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/#findComment-1595695 Share on other sites More sharing options...
ginerjm Posted April 25, 2022 Share Posted April 25, 2022 (edited) I continued trying to fix it. Used Braces and extra escape chars but no luck. Weird. Edited April 25, 2022 by ginerjm Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/#findComment-1595696 Share on other sites More sharing options...
Solution Barand Posted April 25, 2022 Solution Share Posted April 25, 2022 (edited) Curly braces should do the trick $d_row['FormId'] = '98765'; echo "<td><a href='delete.php?user_id={$d_row['FormId']}' onclick=\"return confirm('Are you sure?')\">Delete</a></td>"; giving <td><a href="delete.php?user_id=98765" onclick="return confirm('Are you sure?')">Delete</a></td> Edited April 25, 2022 by Barand Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/#findComment-1595697 Share on other sites More sharing options...
ginerjm Posted April 25, 2022 Share Posted April 25, 2022 So it must of been trying to handle the extra quotes inside the braces that killed me. Another learning moment. Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/#findComment-1595698 Share on other sites More sharing options...
webdeveloper123 Posted April 25, 2022 Author Share Posted April 25, 2022 that did it barand! Many thanks to you both! Quote Link to comment https://forums.phpfreaks.com/topic/314727-echo-javascript-inside-anchor-element/#findComment-1595700 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.