Embedding Javascript into PHP/HTML

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
TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Embedding Javascript into PHP/HTML

Post by TheOracle »

Hi All,

I am trying to write a basic function which just uses a while loop to display a table with data returned from a select statement.

One of the columns contains a string which I want as a hyperlink. This is not a problem in itself, but I want the hyperlink to produce a pop-up.

Unfortunately it doesn't seem possible to incorporate the:

onclick="function('url?id='.$variable['name'].' ');"

into the hyperlink because there are too many apostrophes/speech marks. I also can't create this as a variable external to the function as it won't pick up the correct variable in the hyperlink.

Does anyone have a working example that I can look at, or does anyone have any advice they can give me?

Many thanks,
User avatar
patrikG
DevNet Master
Posts: 4235
Joined: Thu Aug 15, 2002 5:53 am
Location: Sussex, UK

Post by patrikG »

TheOracle
Forum Commoner
Posts: 64
Joined: Mon Nov 22, 2004 4:56 am
Location: Bedford, UK

Post by TheOracle »

Thanks, but I'm not entirely sure what to do with that? Can you give me an example based on javascript?
User avatar
CoderGoblin
DevNet Resident
Posts: 1425
Joined: Tue Mar 16, 2004 10:03 am
Location: Aachen, Germany

Post by CoderGoblin »

I think what you are after can be achieved with the escape character.

Code: Select all

$url=urlencode("mylink?id=$variableї'name'];
echo("<a href="#" onclick="function('$url');"");
I would advise you to look up urlencode to know what is is doing and understand why you should use it.
Last edited by CoderGoblin on Tue Mar 01, 2005 5:25 am, edited 1 time in total.
guest
Forum Commoner
Posts: 25
Joined: Sat Nov 22, 2003 11:50 pm

Post by guest »

<A HREF="whatever.php?a=b&c=d" target="_blank">Message</A>



Scottie_Too_Hottie7
Post Reply