| | |
Function works and then says not defined
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 227
Reputation:
Solved Threads: 18
Hi,
I have some code to dynamically retrieve one of three AJAX files and insert it into a DIV
The Javascript is
And the HTML that triggers the actions is
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
Regards,
Sam Rudge
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)
function createajax() { var Ajax; try{ Ajax = new XMLHttpRequest(); } catch (e){ try{ Ajax = new ActiveXObject("Msxml2.XMLHTTP"); } catch (e) { try{ Ajax = new ActiveXObject("Microsoft.XMLHTTP"); } catch (e){ alert("Error!!!"); return false; } } } return Ajax; } function basicAjaxSwitch(File, Recipient, Animate) { if ( Animate == true ) { Animation(document.getElementById(Recipient)).duration(100).from('opacity', 1).to('opacity', 0).go(); } basicAjaxSwitch = createajax(); basicAjaxSwitch.onreadystatechange = function(){ if(basicAjaxSwitch.readyState == 4){ if ( Animate == true ) { Animation(document.getElementById(Recipient)).duration(100).checkpoint().duration(100).from('opacity', 0).to('opacity', 1).go(); setTimeout('document.getElementById("'+Recipient+'").innerHTML = basicAjaxSwitch.responseText;', 100); } else { document.getElementById(Recipient).innerHTML = basicAjaxSwitch.responseText; } } } basicAjaxSwitch.open("GET", "/ajax/"+File, true); basicAjaxSwitch.send(null); } function changesidebarinfo(changeto) { if ( changeto == 'login' ) { Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '0px').duration(100).go(); Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#FFF').go(); Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#000').go(); Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#000').go(); basicAjaxSwitch('contentinfo/login.php', 'main_layout_rsbinfo_container', true); } else if ( changeto == 'join' ) { Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '50px').duration(100).go(); Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#000').go(); Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#FFF').go(); Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#000').go(); basicAjaxSwitch('contentinfo/join.php', 'main_layout_rsbinfo_container', true); } else if ( changeto == 'about' ) { Animation(document.getElementById('main_layout_accountlinks_background')).to('left', '100px').duration(100).go(); Animation(document.getElementById('main_layout_accountlinks_login')).duration(100).to('color', '#000').go(); Animation(document.getElementById('main_layout_accountlinks_signup')).duration(100).to('color', '#000').go(); Animation(document.getElementById('main_layout_accountlinks_about')).duration(100).to('color', '#FFF').go(); basicAjaxSwitch('contentinfo/about.php', 'main_layout_rsbinfo_container', true); } }
And the HTML that triggers the actions is
HTML Syntax (Toggle Plain Text)
<div id="main_layout_accountlinks"> <div id="main_layout_accountlinks_background"> </div> <div id="main_layout_accountlinks_login" onclick="changesidebarinfo('login');">Log In</div> <div id="main_layout_accountlinks_signup" onclick="changesidebarinfo('join');">Join</div> <div id="main_layout_accountlinks_about" onclick="changesidebarinfo('about');">About</div> </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)
basicAjaxSwitch is not a function changesidebarinfo("login")site.js (line 61) function onclick(event) { changesidebarinfo("login"); }(click clientX=816, clientY=41)2 (line 2) [Break on this error] basicAjaxSwitch('contentinfo/login.php...'main_layout_rsbinfo_container', true);\n
Regards,
Sam Rudge
Last edited by samarudge; 19 Days Ago at 11:44 am.
My Blog, Life and everything that matters to me - SamRudge.co.uk
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
2x Macbook Pro's, 1x Mac Pro, 1x iMac, 2x Macbook's running Fedora linux - In conclusion, I hate windows =)
1
#2 19 Days Ago
Inside the function basicAjaxSwitch you are defining a variable basicAjaxSwitch so it's being overwritten. Just use a different variable name inside the function.
GCS d- s+ a-->? C++(++++) UL+++ P+>+++ L+++ E--- W+++
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
N+ o K w++(---) O? !M- V PS+>++ PE+ Y+ PGP !t- 5? X- R tv+
b+>++ DI+ D G++>+++ e+ h+>++ r y+
PMs asking for help will not be answered, post on the forums. That's what they're there for.
![]() |
Similar Threads
- dont understand a simple function pointer code (C++)
- how this function works for poisson dist?? (C++)
- Using function parameters defined in if statement (C++)
- DLL Function Call (C++)
- Need a way to make 1 function accessible to all (Python)
- Some issues with #define "string" and the write function (unix socket related). (C)
- getline function error (C++)
- Determine in which file a user function is defined? (PHP)
- Program works... now I need to create a function, HELP! (C)
- Function that returns void (C++)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: New web design need help connecting sql database to display content in a form mask
- Next Thread: Aptana Studio Nokia WRT RSS Reader help
| Thread Tools | Search this Thread |
ajax ajaxcode ajaxexample ajaxhelp ajaxjspservlets animate automatically beta box browser bug calendar captchaformproblem checkbox child close column createrange() css cursor date debugger dependent disablefirebug dom download dropdown editor element embed engine error events explorer ext file form forms getselection google gwt gxt hiddenvalue highlightedword hint html htmlform ie7 ie8 iframe images internet java javascript javascripthelp2020 jawascriptruntimeerror jquery jsf jsfile jump libcurl math media microsoft mimic object onmouseoutdivproblem onreadystatechange parent paypal pdf php player position post problem programming progressbar regex runtime scriptlets scroll search security select shopping size software sql text textarea unicode w3c web website window windowofwords windowsxp wysiwyg \n






