954,157 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

return confirm () in php

I've got a simple question: how can I make an onclick return confirm event work inside PHP tags.

<HTML>
<BODY>

<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>

<?PHP

ECHO "<a href='delete.php' OnClick='return confirm('blah blah');'> Click here </a>";

?>

</BODY>
</HTML>


the first link is a simple html link with an onclick event that displays a message that allows the user to confirm the link or cancel it. canceling it will stop the link from loading.

but when I ported it inside the php tags ( and changed the "" in the link code to ' ' in order for it to work with no errore. the return confirm event will not trigger and the page will load just as though there were no onclick event.

there has to be a way to make this work with php ( since it would be absurd for it not to work inside php tags ).

So please help me out with this.

marcmm
Light Poster
42 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

Use escape character which is a backslash (\)

<HTML>
<BODY>

<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>

<?PHP

ECHO "<a href=\"delete.php\" OnClick=\"return confirm('blah blah');\"> Click here </a>";

?>

</BODY>
</HTML>
sikka_varun
Junior Poster in Training
94 posts since Dec 2008
Reputation Points: 11
Solved Threads: 12
 

such a simple answere. thank you. problem solved.

marcmm
Light Poster
42 posts since Oct 2008
Reputation Points: 10
Solved Threads: 0
 

you can also use single quotes to surround the text without have to escape the double quotes inside.

ex.

echo '<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>';


just thought i would point that out.

kkeith29
Nearly a Posting Virtuoso
1,353 posts since Jun 2007
Reputation Points: 235
Solved Threads: 195
 

Hi kkeith29,

This thing you provided will not work...
Because the single quotes before the blah blah will point out an error..

single quote started before echo '<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>';

sikka_varun
Junior Poster in Training
94 posts since Dec 2008
Reputation Points: 11
Solved Threads: 12
 

sorry, forgot to escape the single quotes. thanks for pointing that out.

kkeith29
Nearly a Posting Virtuoso
1,353 posts since Jun 2007
Reputation Points: 235
Solved Threads: 195
 

Hi, when I use return confirm
the title of the message shows the url of my page for example: the page say http://localhost..., you can change that title?

akmotta
Newbie Poster
1 post since Feb 2010
Reputation Points: 10
Solved Threads: 0
 

This question has already been solved

Post: Markdown Syntax: Formatting Help
You