| | |
return confirm () in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: Oct 2008
Posts: 42
Reputation:
Solved Threads: 0
I've got a simple question: how can I make an onclick return confirm event work inside PHP tags.
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.
PHP Syntax (Toggle Plain Text)
<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.
Use escape character which is a backslash (\)
php Syntax (Toggle Plain Text)
<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>
you can also use single quotes to surround the text without have to escape the double quotes inside.
ex.
just thought i would point that out.
ex.
PHP Syntax (Toggle Plain Text)
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.
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..
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.
![]() |
Similar Threads
- how can i make php alert pop ups just like in javascript. (PHP)
- Stopping PHP (JavaScript / DHTML / AJAX)
- Javescript within PHP (PHP)
- javascript+php (JavaScript / DHTML / AJAX)
Other Threads in the PHP Forum
- Previous Thread: $_FILES and sessions
- Next Thread: Changing string to date help
| Thread Tools | Search this Thread |
ajax apache api array beginner binary broken button cakephp checkbox class cms code countingeverycharactersfromastring crack cron curl database date display dynamic echo email error fcc file files folder form forms freelancing function functions google href htaccess html image include incode insert integration ip java javascript joomla limit link login loop mail match menu method mlm mod_rewrite multiple mysql oop pageing pagerank paypal pdf php problem query radio random recursion recursiveloop regex remote script search server sessions sms soap source space sql strip_tags subversion support! syntax system table template tutorial update upload url validator variable video virus web window.onbeforeunload=closeme; xml youtube






