Page 1 of 1

Javascript function in Onclick Event - PHP

Posted: Wed May 18, 2005 8:56 am
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

Posted: Wed May 18, 2005 8:59 am
by JayBird

Code: Select all

echo"<td align=\"center\"><a href=\"elimina_cliente.php?codcliske=$codcliske&ragsociale1=$ragsociale1\" onClick=\"javascript:alert(\"test\");\" >

Posted: Wed May 18, 2005 9:37 am
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>";

Posted: Wed May 18, 2005 9:43 am
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:

Posted: Wed May 18, 2005 10:38 am
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.