473,830 Members | 2,091 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

getting a js fancybox script to work

3 New Member
I have been developing an oscommerce store and everything is fine except for a few little ajax/javascript commands that I cant get to work, so I thought I would post here for some answers.

On my product info page I have a drop down box with this script attached to it
Expand|Select|Wrap|Line Numbers
  1. <script language="javascript">
  2.  
  3. function createRequestObject() {
  4. var req;
  5.  
  6. if(window.XMLHttpRequest){
  7. req = new XMLHttpRequest();
  8.  
  9. } else if(window.ActiveXObject) {
  10. req = new ActiveXObject("Microsoft.XMLHTTP");
  11.  
  12. } else {
  13. req = NULL;
  14. alert('Problem creating object hetXMLHttpRequest');
  15. }
  16. return req;
  17. }
  18. var http = createRequestObject();
  19.  
  20. function sendRequestSearch(iets) {
  21. http.open('get', 'ajaximage.php?search='+iets);
  22. http.onreadystatechange = handleResponseSearch;
  23. http.send(null);
  24. }
  25.  
  26. function handleResponseSearch() {
  27. if(http.readyState == 4 && http.status == 200){
  28. if(http.responseText) {
  29. document.getElementById("search_results").innerHTML = http.responseText;
  30.           } else {
  31.              document.getElementById("search_results").innerHTML = " &nbsp; ";
  32.           }
  33.        } else {
  34.           document.getElementById("search_results").innerHTML = " &nbsp; ";
  35.        }    }
  36. </script>
  37.  
I then have a <div> called search_results which the above loads the ajaximage.php page into. (I think thats what it does??)

ajaximage.php
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2. require('includes/application_top.php');
  3. require(DIR_WS_LANGUAGES . $language . '/' . FILENAME_PRODUCT_INFO);
  4.  
  5. $id = $_GET['search'];
  6. $options_query = tep_db_query("select pov.products_options_values_id, pov.products_options_values_thumbnail from " . TABLE_PRODUCTS_OPTIONS_VALUES . " pov where pov.products_options_values_id = '" .$id . "'");
  7. $options = tep_db_fetch_array($options_query);
  8.  
  9. if($options['products_options_values_thumbnail'] != '' && OPTIONS_IMAGES_CLICK_ENLARGE == 'true')
  10. {
  11. echo "<a id='single_image' href='./images/options/".$options['products_options_values_thumbnail'] ."'>" . "<img src=./images/options/".$options['products_options_values_thumbnail']." width=300 class='noBorder'></a>";
  12. }
  13. if($options['products_options_values_thumbnail'] == '' && OPTIONS_IMAGES_CLICK_ENLARGE == 'true')
  14. {
  15. echo TEXT_IMAGE_NOT_FOUND;
  16. }
  17. if($options['products_options_values_thumbnail'] != '' && OPTIONS_IMAGES_CLICK_ENLARGE == 'false')
  18. {
  19. echo "<img src=./images/options/".$options['products_options_values_thumbnail']." width=300>";
  20. }
  21. ?> 
  22. <?php require('includes/application_bottom.php'); ?>
  23.  
When the product info page is loaded I have an image already in the search_results div
Expand|Select|Wrap|Line Numbers
  1. <div id="search_results"><?php echo "<a id='single_image' href='./images/options/".$options['products_options_values_thumbnail'] ."'>" . "<img src=./images/options/".$options['products_options_values_thumbnail']." width=300 class='noBorder'></a>"; ?></div>
and when a user changes the drop down box the image changes to the relevant one. My fancybox zoom javascript works on the initial image that loads but when the script runs to change the image in the search_results div, fancybox zoom doesn't work.

I have tried entering the javascript into the php echo on the ajaximage.php page like so
Expand|Select|Wrap|Line Numbers
  1. echo "<script type='text/javascript' src='./javascripts/jquery-1.3.2.min.js'></script>
  2. <script type='text/javascript' src='./fancybox/jquery.fancybox-1.3.1.pack.js'></script>
  3. <script type='text/javascript' src='./fancybox/jquery.easing-1.3.pack.js'></script>
  4. <link rel='stylesheet' href='./fancybox/jquery.fancybox-1.3.1.css' type='text/css' media='screen' />
  5. <script language='javascript'>
  6. $(document).ready(function() {
  7.  
  8.     /* This is basic - uses default settings */
  9.  
  10.     $('a#single_image').fancybox({
  11.     'transitionIn'    : 'elastic',
  12.                 'transitionOut'    : 'elastic',
  13.     'titlePosition'    : 'over'
  14.  
  15.     });
  16.  
  17.     /* Using custom settings */
  18.  
  19.     $('a#inline').fancybox({
  20.         'hideOnContentClick': true
  21.     });
  22.  
  23. });
  24. </script> <a id='single_image' href='./images/options/".$options['products_options_values_thumbnail'] ."'>" . "<img src=./images/options/".$options['products_options_values_thumbnail']." width=300 class='noBorder'></a>";
  25.  
but still nothing happens, it just loads the image by itself in the page and doesn't zoom.

If I type ajaximage.php?s earch=24 into my browser it loads the image and the fancybox works... So I'm guessing it has something to do with the onstatechange loading the first script that doesn't process the html? I don't actually know??

If anyone could help that would be great, I've been trying to solve this for the last 2 days.

Cheers

Nick
Jul 19 '10 #1
5 4038
acoder
16,027 Recognized Expert Moderator MVP
Are you using this? Check the howto.
Jul 20 '10 #2
nicksull
3 New Member
Hi acoder,

Thanks for your reply.

I've already installed fancybox using the howto and it works fine when the page ajaximage.php is loaded in a browser by itself.

The problem is I have an ajax script attached to a drop down to load that ajaximage.php as an external page into a div, that's when the javascript doesn't work.

I have done some research and been reading that the scripts on the called in page needs to be evaled explicitly, but I have no idea how to do that. Sorry only have a tiny little bit of knowledge about javascript/ajax.
Jul 20 '10 #3
acoder
16,027 Recognized Expert Moderator MVP
Yes, eval is one way to run scripts from the called page, or you can include it on the parent page.

However, you already have the fancy box code in the parent page. All you need to do is call it appropriately, e.g. call this in your call back function after the images have been loaded:
Expand|Select|Wrap|Line Numbers
  1. $('a#single_image').fancybox({
  2.     'transitionIn'    : 'elastic',
  3.                 'transitionOut'    : 'elastic',
  4.     'titlePosition'    : 'over'
  5.  
  6.     });
Jul 21 '10 #4
nicksull
3 New Member
acoder you're a legend!

thank you very much!

learning new stuff (with a bit of help) is fun...
Jul 22 '10 #5
acoder
16,027 Recognized Expert Moderator MVP
No problem, glad you got it working :)
Jul 22 '10 #6

Sign in to post your reply or Sign up for a free account.

Similar topics

3
1860
by: Steve Richter | last post by:
How does the following javascript work? After the first script runs the variables "sGeobytesCity", "sGeobytesRegion" and "sGeobytesCountry" contain values that have been set somehow by the "src=http://gd.geobytes.com..." how does it do that? It appears to pass the string "variables=GeobytesCountry, ..." and on return the document variable "sGeobytesCountry" contains a value!! thanks,
1
2098
by: mikaelsnavy | last post by:
Hi, I'm building an e-commerce website for a friend and am having a bit of trouble. I'm on the checkout part where I need to submit the information to the payment gateway. The gateway has no support for php. I have the script in VBScript and JavaScript, but have run into dead ends with both. Here is what the script needs to do: 1. Create the XML object. 2. Set the objects address to the api and the request header also 3. Send the data. 4....
1
2738
by: Darrel Yurychuk | last post by:
I'm having a problem getting the window.onresize to work properly. Here is a simple test case I wrote: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> <html> <head> <title>Test window.onresize</title> <script type="text/javascript"> function resize_func() {
9
1536
by: Freebird | last post by:
Hello everyone ... I've a problem in here, I need to make a 70 000 rows insert, and it's taking a lot more than 30 seconds, my problem is that it will be a script that will work in many servers, I've no idea of how many, the set_time_limit does not work for many of the servers out there, so I'm in trouble, I've tryed to do a refresh every 100 inserts, but it doesn't work at all, does anyone have a class, function or piece of code that...
4
1494
by: fletch | last post by:
Hi all. I am rerouting all requests through a script, dispatch.php, using a ..htaccess file, except on a few directories. dispatch.php then decides what code needs to be loaded to return the correct info. When calling the site root http://primo.localhost/ the result is sent as text/plain and is rendered as such by Firefox (though interestingly not IE, which renders the html)
10
2290
by: jonathan184 | last post by:
Hi I tried getting this to work through dreamweaver but it did not. So i found a n example on the internet , i followed everything exactly the search script does not work. Could somebody help me this please. Thanks for your help in advance. The form and script are on the same page. <?php require_once('../Connections/rs_ais.php'); ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"...
10
4376
by: Ohmster | last post by:
I am trying to use this cool script that some MIT guy wrote and it just does not work, I get a stream of errors when I try to run it. It is supposed to visit a URL and snag all of the pictures on the site. Here is the script: http://web.mit.edu/pgbovine/www/image-harvester/image-harvester.py Here is my output when I try to run it on my Fedora 6 machine: $ image-harvester.py http://public.fotki.com/DaGennelman/
4
2197
by: Timothy Smith | last post by:
Not sure exactly what I need to do to get wxPython to work on either of my Macs. (One's a notebook running Tiger (OS X 10.4.11), the other a Mac Pro running Leopard (10.5.1.)) I downloaded what should be the latest binary, and it installed without error. So Python comes up as $ python -V Python 2.5.1 $ ls -l /usr/bin/python
1
2691
by: ced69 | last post by:
having trouble getting marquee to work get object required errors tring t <title>This Month at the Chamberlain Civic Center</title> <link href="styles.css" rel="stylesheet" type="text/css" /> <script src="Dunbarlab9.js" type="text/javascript"></script> <script type="text/javascript">
0
9641
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10769
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9310
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7740
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5777
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4408
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3956
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3072
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.