Jump to content

(SOLVED) Embedding PHP within HTML/ Javascript (Quick Question?)


Solarpitch

Recommended Posts

Hey Guys,

Just wanted to know if the following format is correct, doesnt seem to be working for me at all.

[code]

<?php

$image1 = "fusion_02.jpg";
$image2 = "fusion_03.jpg";
$image3 = "fusion_04.jpg";

?>

function image (img)
{
document.images['image'].src = img;
}

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

Bascially, it changes the image on a page based on the number that is selected. It seems to work when I have it like below, but not above. Just wondering if the above is the correct way to embed the PHP content?

This way works fine...
[code]
<a href="javascript:image('designs/fusion_03.jpg');">1</a>
<a href="javascript:image('designs/fusion_03.jpg');">2</a>
<a href="javascript:image('designs/fusion_04.jpg');">3</a>
[/code]
[code]
<a href="javascript:image('designs/"<?php echo $image1; ?>"');">1</a>
<a href="javascript:image('designs/"<?php echo $image2; ?>"');">2</a>
<a href="javascript:image('designs/"<?php echo $image3; ?>"');">3</a>
[/code]
That should do
Ted
The default image will be the first image in the result. There will be 3 images displayed and $image 1 will be the default. I also have the following line of code in my "php_database" page.

[code]
<img name='image' src='designs/".$image1."' style='border: 1px solid rgb(0, 0, 0);' border='0' width='200' height='200' title='blah' />
[/code]
Why do you have the double quotes surrounding the value echoed via PHP?
[code]
<a href="javascript:image('designs/"<?php echo $image1; ?>"');">1</a>
<a href="javascript:image('designs/"<?php echo $image2; ?>"');">2</a>
<a href="javascript:image('designs/"<?php echo $image3; ?>"');">3</a>
[/code]

Remove those double quotes and it should be ok:
[code]
<a href="javascript:image('designs/<?php echo $image1; ?>');">1</a>
<a href="javascript:image('designs/<?php echo $image2; ?>');">2</a>
<a href="javascript:image('designs/<?php echo $image3; ?>');">3</a>
[/code]

Ken
Hi Guys,

Na . . I tried that already! Still no Joy . . I bet its something god dam simple . . heres my code again

view_ad.php
[code]

<?php
$image1 = "fusion_02.jpg"; //I'll be calling these from a DB when I get it working
$image2 = "fusion_03.jpg";
$image3 = "fusion_04.jpg";
?>

script>

function image (img) {
document.images['image'].src = img;
}

</script>

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

php_database.php
[code]
<h1 class='underline'>New Callaway Big Bertha <span>(Uploaded on: 17-12-2006)</span?></br>
<div id='container'>
<h1 class='underline'>
<div id='images'>



  <img name='image' src='designs/".$image1."' style='border: 1px solid rgb(0, 0, 0);' border='0' width='200' height='200' title='blah' />
 
The above line displays the image
****************************************

</div>
<div id='details'>
  <ul>
  <li><span>Section:</span> Mens</li>
  <li><span>Class:</span> Drivers</li>
  <li><span>Make:</span> Callaway</li>
  </ul>
  <ul>
  <li><span>Tel:</span> 0876141487</li>
  <li><span>Contact Name:</span> Andrew</li>
  <li><span>County:</span> Dublin</li>
  </ul>
</div>
<div id='text'>
  <p>  Brand new Callaway Big Bertha Driver. Comes with 65 stiff graffaloy shaft, 9 degree loft and original head cover. No Time wasters, first to see will buy. <div class='clearb'></div>
<h2 class='underline'>Price: &euro;400
</div>
[/code]

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.