Javascript function in Onclick Event - PHP

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
paolo
Forum Newbie
Posts: 15
Joined: Sat May 14, 2005 6:06 am

Javascript function in Onclick Event - PHP

Post by paolo »

Hello,

I'm having some troubles getting my script to work, I give the explanation first than show the code.
I make a table fetching values from MySQL DB, the table is a list of people, I've made a link to a page to delete selected person,I want to show an advertisment box before proceeding.
The problem is I have to call Javascript's window from PHP...how do I do that?? Here's my example with the alert() function instead of the final function

Code: Select all

echo"<td align=\"center\">
<a href=\"elimina_cliente.php?codcliske=$codcliske&ragsociale1=$ragsociale1\" 
				onClick=\"<script language=\"javascript\">alert(\"test\")</script>\" >
which doesn't want to work... any suggestion??
Thanks in advance
Paolo
User avatar
JayBird
Admin
Posts: 4524
Joined: Wed Aug 13, 2003 7:02 am
Location: York, UK
Contact:

Post by JayBird »

Code: Select all

echo"<td align=\"center\"><a href=\"elimina_cliente.php?codcliske=$codcliske&ragsociale1=$ragsociale1\" onClick=\"javascript:alert(\"test\");\" >
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

work that will not, double quotes inside your js portion you have, plus need "javascript:" you don't when using onclick events (already assumed it is).

Code: Select all

echo "<a href=\"yourpage.php\" onClick=\"alert('hello there')\">Clicky Me</a>";
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

Not a solution as one has already been given. More of an observation...

Personally for a page like this I would get extremely annoyed by the "popups" and as such would never never see me go to the site again. If there was no other choice than use the site I would disable the javascript. You may want to think about other methods of having less "unobtusive" advertising. Just my opinion :wink:
User avatar
phpScott
DevNet Resident
Posts: 1206
Joined: Wed Oct 09, 2002 6:51 pm
Location: Keele, U.K.

Post by phpScott »

I agree with coderGoblin on the advertisements but any good pop-up blocker will stop it if it hasn't been user initiated.
Post Reply