vanvoquan Posted November 11, 2010 Share Posted November 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted November 11, 2010 Author Share Posted November 11, 2010 Anybody? Quote Link to comment Share on other sites More sharing options...
Rifts Posted November 11, 2010 Share Posted November 11, 2010 yse php can work in javascript Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 11, 2010 Share Posted November 11, 2010 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 Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted November 12, 2010 Author Share Posted November 12, 2010 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 Quote Link to comment Share on other sites More sharing options...
Dragosvr92 Posted November 12, 2010 Share Posted November 12, 2010 Your script has two bugs at the <?php tags the PHP Tags should be <?echo "Hello";?> or <?php echo "Hello";?> dont add the space between <? and php make it <?php Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted November 12, 2010 Author Share Posted November 12, 2010 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> Quote Link to comment Share on other sites More sharing options...
kenrbnsn Posted November 12, 2010 Share Posted November 12, 2010 If you do a "show source" in your browser do you see the Javascript that you expect? Ken Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted November 12, 2010 Author Share Posted November 12, 2010 Thanks for replying Kenrbnsn. When i do a show soure, it didn't show the picture file name. it only show the folder "images". <img src="images/" border="0" alt=""> how can i fix this ? Thanks for any helps. vanvoquan Quote Link to comment Share on other sites More sharing options...
joel24 Posted November 12, 2010 Share Posted November 12, 2010 what is this tep_image() function you're calling? are you executing the database query to retrieve the $product_info array? try echo exit($product_info['product_image_2'])); [/url] and see what it prints. Quote Link to comment Share on other sites More sharing options...
vanvoquan Posted November 14, 2010 Author Share Posted November 14, 2010 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); ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.