return confirm () in php

Thread Solved

Join Date: Oct 2008
Posts: 42
Reputation: marcmm is an unknown quantity at this point 
Solved Threads: 0
marcmm marcmm is offline Offline
Light Poster

return confirm () in php

 
0
  #1
Dec 18th, 2008
I've got a simple question: how can I make an onclick return confirm event work inside PHP tags.

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: return confirm () in php

 
0
  #2
Dec 18th, 2008
Use escape character which is a backslash (\)

  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>
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Oct 2008
Posts: 42
Reputation: marcmm is an unknown quantity at this point 
Solved Threads: 0
marcmm marcmm is offline Offline
Light Poster

Re: return confirm () in php

 
0
  #3
Dec 18th, 2008
such a simple answere. thank you. problem solved.
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: return confirm () in php

 
0
  #4
Dec 18th, 2008
you can also use single quotes to surround the text without have to escape the double quotes inside.

ex.

  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.
Reply With Quote Quick reply to this message  
Join Date: Dec 2008
Posts: 94
Reputation: sikka_varun is an unknown quantity at this point 
Solved Threads: 11
sikka_varun's Avatar
sikka_varun sikka_varun is offline Offline
Junior Poster in Training

Re: return confirm () in php

 
0
  #5
Dec 19th, 2008
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.
VâRûN
---Happy to Help---
sikka_varun@yahoo.com
Reply With Quote Quick reply to this message  
Join Date: Jun 2007
Posts: 1,227
Reputation: kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about kkeith29 has a spectacular aura about 
Solved Threads: 167
kkeith29's Avatar
kkeith29 kkeith29 is offline Offline
Nearly a Posting Virtuoso

Re: return confirm () in php

 
0
  #6
Dec 19th, 2008
sorry, forgot to escape the single quotes. thanks for pointing that out.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Similar Threads
Other Threads in the PHP Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC