Jump to content

[SOLVED] PHP + javascript mouse over gallery help


ashadweb

Recommended Posts

Hi,

 

I making a web site and i have a code but this is not working properly dont knw why help me code is bellow

 

##############################################################

JAVA SCRIPT

 

<script type="text/javascript">

 

if (document.images) {

image0 = new Image;

image1 = new Image;

image2 = new Image;

 

image0.src = "<?= $im_array[0] ?>";

image1.src = "<?= $im_array[1] ?>";

image2.src = "<?= $im_array[2] ?>";

 

} else {

image0 = '';

image1 = '';

image2 = '';

document.rollimg = '';

}

</script>

 

#################################

 

PHP CODE

 

<?= "<span onmouseover=document.rollimg.src=image0.src;>

<img src=\"../cars_images/$im_array[0]\" class=thumb_img width=150 height=150 alt=1\">

</span> " ?>

<?= "<span onmouseover=document.rollimg.src=image1.src;>

<img src=\"../cars_images/$im_array[1]\" class=thumb_img width=150 height=150 alt=2\">

</span>" ?>

<?= "<span onmouseover=document.rollimg.src=image2.src;>

<img src=\"../cars_images/$im_array[2]\" class=thumb_img width=150 height=150 alt=3\">

</span>" ?>

 

</p>

<p align="center">

<?=

  "<img src=\"../cars_images/$im_array[0]\" class=thumb_img width=150 height=150 alt=Larger version of one of the smaller images above name=rollimg\">"

?>

</p>   

 

######################################

 

 

Link to comment
Share on other sites

First replace "<?=" with "<?php echo" so that the PHP actually runs.

 

Next add quotes around attribute values and onmouseover events, e.g. alt="Larger version of one of the smaller images above", onmouseover="document.rollimg.src=image0.src;"

It is good practice to surround all attributes with quotation marks. Some, such as numbers, may not need them but most attributes will, so get into good habits.

 

Then change  name=rollimg  to  id="rollimg"  and  document.rollimg  to  document.getElementById("rollimg")  .

Referring to elements using document.name syntax will not work in most modern browsers.

 

Then try your webpage again.

 

 

And use the  [ code ]  tags on the forum when posting code. It's the "#" button just above the smilies.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.