943,753 Members | Top Members by Rank

Ad:
  • PHP Discussion Thread
  • Marked Solved
  • Views: 9756
  • PHP RSS
Dec 18th, 2008
0

return confirm () in php

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

PHP Syntax (Toggle Plain Text)
  1. <HTML>
  2. <BODY>
  3.  
  4. <a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>
  5.  
  6. <?PHP
  7.  
  8. ECHO "<a href='delete.php' OnClick='return confirm('blah blah');'> Click here </a>";
  9.  
  10. ?>
  11.  
  12. </BODY>
  13. </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.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
marcmm is offline Offline
42 posts
since Oct 2008
Dec 18th, 2008
0

Re: return confirm () in php

Use escape character which is a backslash (\)

php Syntax (Toggle Plain Text)
  1. <HTML>
  2. <BODY>
  3.  
  4. <a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>
  5.  
  6. <?PHP
  7.  
  8. ECHO "<a href=\"delete.php\" OnClick=\"return confirm('blah blah');\"> Click here </a>";
  9.  
  10. ?>
  11.  
  12. </BODY>
  13. </HTML>
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Dec 18th, 2008
0

Re: return confirm () in php

such a simple answere. thank you. problem solved.
Reputation Points: 10
Solved Threads: 0
Light Poster
marcmm is offline Offline
42 posts
since Oct 2008
Dec 18th, 2008
0

Re: return confirm () in php

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

ex.

PHP Syntax (Toggle Plain Text)
  1. echo '<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>';

just thought i would point that out.
Last edited by kkeith29; Dec 18th, 2008 at 4:03 pm.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Dec 19th, 2008
0

Re: return confirm () in php

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 <a and it ends at confirm( ... and wt after that.. there's blah blah and then again single quotes..
This will be an error..

echo '<a href="delete.php" OnClick="return confirm('blah blah');"> Click here </a>';
Last edited by peter_budo; Dec 21st, 2008 at 4:45 am. Reason: Keep It Organized - For easy readability, always wrap programming code within posts in [code] (code blocks) and [icode] (inline code) tags.
Reputation Points: 11
Solved Threads: 12
Junior Poster in Training
sikka_varun is offline Offline
94 posts
since Dec 2008
Dec 19th, 2008
0

Re: return confirm () in php

sorry, forgot to escape the single quotes. thanks for pointing that out.
Reputation Points: 235
Solved Threads: 193
Nearly a Posting Virtuoso
kkeith29 is offline Offline
1,315 posts
since Jun 2007
Feb 12th, 2010
0
Re: return confirm () in php
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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
akmotta is offline Offline
1 posts
since Feb 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in PHP Forum Timeline: Change 599 into 5.99
Next Thread in PHP Forum Timeline: Php mysql update set





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC