woodsonoversoul Posted February 16, 2009 Share Posted February 16, 2009 Hi all, it seems like some times this works and other times it doesn't and I can't figure out why. My problem is that this line of html: <image id="expImg" src="16-arrow-right.png" onclick="expand('resultsDiv', 'artist', 'artist');"></image> Does not call this function: function expand(group, artist, expandTo){ alert("expand called"); if(group == 'resultsDiv'){ var calling_element = document.getElementById('result_root'); } else{ var calling_element = document.getElementById(group); } var calling_element_img = calling_element.getElementsByTagName('img'); var calling_img_src = calling_element_img[0].getAttribute('src'); if(calling_element_img[0].getAttribute('src') == '16-arrow-right.png'){ calling_element_img[0].setAttribute('src', '16-arrow-down.png'); process(group, artist, expandTo); } else{ calling_element_img[0].setAttribute('src', '16-arrow-right.png'); removeChildren(group); } } even though the script file is referenced in <head>: <script type="text/javascript" src="xml.js"></script> I can post the whole code, but does anyone see any obvious errors? Thanks Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 16, 2009 Share Posted February 16, 2009 What JavaScript errors do you get? Do you have a link to the page? Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted February 16, 2009 Author Share Posted February 16, 2009 I says expand is undefined...btw what javascript debugger/error checker do you recommend Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 17, 2009 Share Posted February 17, 2009 Firebug for Firefox um, well, the function isn't defined. are you absolutely sure the JS file is getting loaded? Quote Link to comment Share on other sites More sharing options...
woodsonoversoul Posted February 18, 2009 Author Share Posted February 18, 2009 I don't understand why it wouldn't be. And the thing is is that it only throws this error sometimes (which is even more unnerving than having a constant error). For instance, I'll go in and change a few things in my javascript file and it will say expand() is not defined, but when I try later in the afternoon it will work fine. What gives? Have you heard about anything like this before? Quote Link to comment Share on other sites More sharing options...
rhodesa Posted February 18, 2009 Share Posted February 18, 2009 there are a lot of factors that cause that. small changes in your HTML can even cause the JavaScript file not to load. also, check to make sure you are not executing any javascript until after the DOM is done loading (load JS if fine, just don't execute any functions). also, check to make sure your browser isn't caching the JS file. an easy solution to this is loading your file with: <script type="text/javascript" src="scripts/myfile.js?_=<?php echo time(); ?>"></script> that way, during development, you know it's loading the latest copy. once in production, i would remove that extra bit of PHP 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.