hello david,
I hv installed some java script on mysite but it has an error using IE in some part of the site. My site is {link saved} (pls hide my url, thanks).
I put the below scripts on the header.
function mycarousel_initCallback(carousel)
{
// Disable autoscrolling if the user clicks the prev or next button.
carousel.buttonNext.bind('click', function() {
carousel.startAuto(0);
});
carousel.buttonPrev.bind('click', function() {
carousel.startAuto(0);
});
// Pause autoscrolling if the user moves with the cursor over the clip.
carousel.clip.hover(function() {
carousel.stopAuto();
}, function() {
carousel.startAuto();
});
};
jQuery(document).ready(function() {
jQuery('#mycarousel').jcarousel({
auto: 2,
wrap: 'last',
initCallback: mycarousel_initCallback
});
});
Thereafter create a new file html/sc2.php and place in the header
<?php
require("html/sc2.php");
?>
When i browse the main page, everything is fine (no error) using IE7. Even when i search for products, it looks ok. But when i browse merchant, category, brand, etc, it gives me error.
The errors are
Line: 2
Char: 1
Code: 0
Error: Syntax error
URL:http://url/category/
The above repeated twice. I think is referring to the below java scripts.
Then another error
Line 36
Char 1
Code 0
Error Object expected
URL:http://url/category/
I was wondering how come when i add javascript on the header, it will show error whereas i hv 2 others javascript working fine when i put the entire script into the html page. (referring to the scroller and date.)
Am curious why some part of the site is ok and some parts don't. Hope you can help.
thanks
jack
Hi David,
You are great man! It works ok. Thank you very much.
Cheers,
Jack
Hello Jack,
Whenever I'm trying to sort JavaScript errors, I always test in Firefox, which gives more information about Syntax Errors. When testing, go to Tools > Error Console, then click "Clear" before browsing to your site...
What seems to be happening in this case is that your code to load the JavaScript contains relative URLs, so they cannot be found (which will of course lead to errors). When you view the source, this is the code in the header:
<script type="text/javascript" src="jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="jquery.jcarousel.pack.js"></script>
<script type="text/javascript" src="jcarousellite_1.0.1.js"></script>
<script type="text/javascript" src="jquery.latest.pack.js"></script>
(I think from what you said in your post that this code is in html/sc2.php).
Instead, this needs to be:
<script type="text/javascript" src="/jquery-1.2.3.pack.js"></script>
<script type="text/javascript" src="/jquery.jcarousel.pack.js"></script>
<script type="text/javascript" src="/jcarousellite_1.0.1.js"></script>
<script type="text/javascript" src="/jquery.latest.pack.js"></script>
- notice the "/" infront of each of the src values. Similarly for the CSS paths, they also need to be prefixed with "/" so that they can be found from all the virtual sub-directories on your site.
That should be all it is!
Cheers,
David.