944,147 Members | Top Members by Rank

Ad:
Nov 3rd, 2009
0

Function works and then says not defined

Expand Post »
Hi,
I have some code to dynamically retrieve one of three AJAX files and insert it into a DIV

The Javascript is
javascript Syntax (Toggle Plain Text)
  1. function createajax() {
  2. var Ajax;
  3. try{
  4. Ajax = new XMLHttpRequest();
  5. } catch (e){
  6. try{
  7. Ajax = new ActiveXObject("Msxml2.XMLHTTP");
  8. } catch (e) {
  9. try{
  10. Ajax = new ActiveXObject("Microsoft.XMLHTTP");
  11. } catch (e){
  12. alert("Error!!!");
  13. return false;
  14. }
  15. }
  16. }
  17. return Ajax;
  18. }
  19.  
  20. function basicAjaxSwitch(File, Recipient, Animate) {
  21. if ( Animate == true ) {
  22. Animation(document.getElementById(Recipient)).duration(100).from('opacity', 1).to('opacity', 0).go();
  23. }
  24. basicAjaxSwitch = createajax();
  25. basicAjaxSwitch.onreadystatechange = function(){
  26. if(basicAjaxSwitch.readyState == 4){
  27. if ( Animate == true ) {
  28. Animation(document.getElementById(Recipient)).duration(100).checkpoint().duration(100).from('opacity', 0).to('opacity', 1).go();
  29. setTimeout('document.getElementById("'+Recipient+'").innerHTML = basicAjaxSwitch.responseText;', 100);
  30. } else {
  31. document.getElementById(Recipient).innerHTML = basicAjaxSwitch.responseText;
  32. }
  33. }
  34. }
  35. basicAjaxSwitch.open("GET", "/ajax/"+File, true);
  36. basicAjaxSwitch.send(null);
  37. }
  38.  
  39. function changesidebarinfo(changeto) {
  40. if ( changeto == 'login' ) {
  41. Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '0px').duration(100).go();
  42. Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#FFF').go();
  43. Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#000').go();
  44. Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#000').go();
  45. basicAjaxSwitch('contentinfo/login.php', 'main_layout_rsbinfo_container', true);
  46. } else if ( changeto == 'join' ) {
  47. Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '50px').duration(100).go();
  48. Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#000').go();
  49. Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#FFF').go();
  50. Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#000').go();
  51. basicAjaxSwitch('contentinfo/join.php', 'main_layout_rsbinfo_container', true);
  52. } else if ( changeto == 'about' ) {
  53. Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '100px').duration(100).go();
  54. Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#000').go();
  55. Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#000').go();
  56. Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#FFF').go();
  57. basicAjaxSwitch('contentinfo/about.php', 'main_layout_rsbinfo_container', true);
  58. }
  59. }

And the HTML that triggers the actions is
HTML Syntax (Toggle Plain Text)
  1. <div id="main_layout_accountlinks">
  2. <div id="main_layout_accountlinks_background">&nbsp;</div>
  3. <div id="main_layout_accountlinks_login" onclick="changesidebarinfo('login');">Log In</div>
  4. <div id="main_layout_accountlinks_signup" onclick="changesidebarinfo('join');">Join</div>
  5. <div id="main_layout_accountlinks_about" onclick="changesidebarinfo('about');">About</div>
  6. </div>

When I click one of the 3 buttons (doesn't matter which) the result is exactly as intended. Then when I click another (or the same) button, nothing happens and Firebug gives the error
text Syntax (Toggle Plain Text)
  1. basicAjaxSwitch is not a function
  2. changesidebarinfo("login")site.js (line 61)
  3. function onclick(event) { changesidebarinfo("login"); }(click clientX=816, clientY=41)2 (line 2)
  4. [Break on this error] basicAjaxSwitch('contentinfo/login.php...'main_layout_rsbinfo_container', true);\n

Regards,
Sam Rudge
Last edited by samarudge; Nov 3rd, 2009 at 11:44 am.
Similar Threads
Reputation Points: 26
Solved Threads: 31
Posting Whiz
samarudge is offline Offline
354 posts
since May 2008
Nov 3rd, 2009
1
Re: Function works and then says not defined
Inside the function basicAjaxSwitch you are defining a variable basicAjaxSwitch so it's being overwritten. Just use a different variable name inside the function.
Sponsor
Reputation Points: 520
Solved Threads: 268
Code Monkey
ShawnCplus is offline Offline
1,564 posts
since Apr 2005

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in JavaScript / DHTML / AJAX Forum Timeline: New web design need help connecting sql database to display content in a form mask
Next Thread in JavaScript / DHTML / AJAX Forum Timeline: Aptana Studio Nokia WRT RSS Reader help





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC