Jump to content

Problem with "echoing" javascript and PHP/ database values


Solarpitch

Recommended Posts

Hey guys,

Just looking for a little help with this. I posted something similar last week but it resolved itself. This is slightly different however.

Basically the following code generates a href to 3 images that are retrieved from the DB. Using Javascript the user can navigate through the 3 images.

The following codes works perfect!

[code]<div style="font-family:Verdana, Arial, Helvetica, sans-serif; font-size:13px; ">&nbsp;&nbsp;&nbsp;&nbsp;View images:

<a href="javascript:image('user_images/<?php echo $image1; ?>');">[1]</a>
<a href="javascript:image('user_images/<?php echo $image2; ?>');">[2]</a>
<a href="javascript:image('user_images/<?php echo $image3; ?>');">[3]</a>
</div>[/code]

however, when I try to generate this code as an "echo" to the page, when the links [1], [2] and [3] are clicked . . noting happens! heres that code . .

[code]echo "<a href='javascript:image('user_images/".$row['image_path1']."');'>[3]</a>"
echo "<a href='javascript:image('user_images/".$row['image_path2']."');'>[2]</a>";
echo "<a href='javascript:image('user_images/".$row['image_path3']."');'>[3]</a>";[/code]


I should also add that when you roll the mouse over the links in the first example, the href displays as..

"javascript:image('user_images/taylormade.jpg');"

however in the bottom example that wont work it displays as..

"javascript:image("

Grateful of some help, cheers
You have problems with your quotes. Try this:
[code]<?php
echo '<a href="javascript:image(' . "'user_images/" . $row['image_path1'] . "');" . '">[3]</a>';
echo '<a href="javascript:image(' . "'user_images/" . $row['image_path2'] . "');" . '">[2]</a>';
echo '<a href="javascript:image(' . "'user_images/" . $row['image_path3'] . "');" . '">[3]</a>';
?>[/code]

Ken

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.