Jump to content

Can Php work inside a javascript ?


vanvoquan

Recommended Posts

Hi everybody. I have this script in the <head></head> tag to help me reload images, so when i put the mouse over image it appear in another location of the table. The problem is i have to put the images manually to the script. Can i automatic put the images with php in the script.

The script look like this:

<script> 
function changeimage(towhat,url){ if (document.images){ document.images.targetimage.src=towhat.src gotolink=url } } function warp(){ window.location=gotolink }
</script> 

<script language="JavaScript1.1"> 
var myimages=new Array() var gotolink="#"
function preloadimages(){ for (i=0;i<preloadimages.arguments.length;i++){ myimages[i]=new Image() myimages[i].src=preloadimages.arguments[i] } } preloadimages("images/plane1.gif","images/plane2.gif") 
</script>

 

So instead of manually put "images/plane1.gif", images/plane2.gif" I want to use something like this:

' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . '

 

So the script look like this:

preloadimages("<? php echo ' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . '  ?>","<? php echo ' . tep_image(DIR_WS_IMAGES . $product_info['product_image_6'], $product_info['products_name'], SMALL_WIDTH_IMAGE, SMALL_HEIGHT_IMAGE, 'hspace="5" vspace="5"') . ' ?>"

 

Any help or suggestions will greatly appriciate.

 

vanvoquan

 

Link to comment
Share on other sites

yse php can work in javascript

 

javascript is executed on the client's machine and PHP is executed on the server machine before the pages are sent to the client/user. So yes PHP will edit the javascript and then once PHP has finished executed, sends it to the client

Link to comment
Share on other sites

Thanks for replying. Can anybody show me why i use php to echo images it didn't work.

 preloadimages("<? php echo  tep_image(DIR_WS_IMAGES . $product_info['product_image_6']) ;  ?>","
<? php echo  tep_image(DIR_WS_IMAGES . $product_info['product_image_6']) ; ?>"

 

Vanvoquan

Link to comment
Share on other sites

So far this is what i have worked for hours. But no idea why when i put the mouse over the text "Plane 1" or "Plane 2" it didn't show the picture in the preloadimages function.

 

Any helps will be million thanks.

 

<html>
<head>

<script>
function changeimage(towhat,url){
if (document.images){
document.images.targetimage.src=towhat.src
gotolink=url
}
}
function warp(){
window.location=gotolink
}

</script>
<script language="JavaScript1.1">
var myimages=new Array()
var gotolink="#"

function preloadimages(){
for (i=0;i<preloadimages.arguments.length;i++){
myimages[i]=new Image()
myimages[i].src=preloadimages.arguments[i]
}
}
preloadimages("<?php echo tep_image(DIR_WS_IMAGES . $product_info['product_image_2']); ?>" , "<?php echo tep_image(DIR_WS_IMAGES . $product_info['product_image_3']); ?>" , "<?php echo tep_image(DIR_WS_IMAGES . $product_info['product_image_4']); ?>" , "<?php echo tep_image(DIR_WS_IMAGES . $product_info['product_image_5']); ?>" , "<?php echo tep_image(DIR_WS_IMAGES . $product_info['product_image_6']); ?>")
</script>

</head>
<body>
<table>
<tr>
<td>

<a href="javascript:warp()"><img src="<?php echo (DIR_WS_IMAGES . $product_info['products_image']); ?>"></a>

</td>
</tr>
<tr>
<td>

<a href="b2.htm" onMouseover="changeimage(myimages[0],this.href)">Plane 1</a> <br>
<a href="f15.htm" onMouseover="changeimage(myimages[1],this.href)">Plane 2</a><br>
<a href="su27.htm" onMouseover="changeimage(myimages[2],this.href)">Plane 3</a><br>
<a href="jet.htm" onMouseover="changeimage(myimages[3],this.href)">Plane 4</a><br>
<a href="boeing.htm" onMouseover="changeimage(myimages[4],this.href)">Plane 5</a><br>

</td>
</tr>
</table>

</body>
</html>

Link to comment
Share on other sites

Thanks for helping guys. I got it working. The reason that just give me only the images folder is that the javascript contain the "preloadimages" function is in the head tag while the sql query is in the body section. So i put one of this query in the head section and it's working fine.

<?php 
$product_info_query1 = tep_db_query("select p.products_id, pd.products_name, pd.products_description, p.products_model, p.products_quantity, p.products_image, p.product_image_2, p.product_image_3, p.product_image_4, p.product_image_5, p.product_image_6, pd.products_url, p.products_price, p.products_tax_class_id, p.products_date_added, p.products_date_available, p.manufacturers_id from " . TABLE_PRODUCTS . " p, " . TABLE_PRODUCTS_DESCRIPTION . " pd where p.products_status = '1' and p.products_id = '" . (int)$HTTP_GET_VARS['products_id'] . "' and pd.products_id = p.products_id and pd.language_id = '" . (int)$languages_id . "'");
    $product_info1 = tep_db_fetch_array($product_info_query1);
?>

 

 

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.