CMellor Posted June 27, 2007 Share Posted June 27, 2007 Hello all, First I'd like to point out that I'm new-ish to Javascript, I don't use it in big chunks, just small. I have made this function, check it out: function callPage(url) { Spry.Utils.setInnerHTML('blah', 'Loading...'); Spry.Utils.loadURL("GET", url, true, callHandle); } function callHandle(req) { Spry.Utils.setInnerHTML('blah', req.xhRequest.responseText); } I use an onClick with a Button to call it: <input name="button" type="button" onclick="callPage('spry_form.php?id=14');" value="Click" /> and the requested text appears here: <div id="blah"></div> I want to use this function more than once and would want to call a new DIV ID each time, but when I try this function: function callPage(url, div) { Spry.Utils.setInnerHTML(div, 'Loading...'); Spry.Utils.loadURL("GET", url, true, callHandle); } function callHandle(req) { Spry.Utils.setInnerHTML(div, req.xhRequest.responseText); } Along with this XHTML: <input name="button" type="button" onclick="callPage('spry_form.php?id=14', 'blah');" value="Click" /> When I click the button, it shows the 'Loading...' text, but doesn't request the file, it just says 'Loading...' all the time. As I stated I'm new-ish with Javascript and not sure what I may have done wrong with this function. If anybody can guide me in the right direction, I would be greatly appreciated, and it would help me a lot! Thanks for taking the time to read, and I look forward to a response, Chris. Quote Link to comment Share on other sites More sharing options...
mainewoods Posted June 29, 2007 Share Posted June 29, 2007 in your second function, the usage of 'div' is undefined at that point: function callPage(url, div) { Spry.Utils.setInnerHTML(div, 'Loading...'); Spry.Utils.loadURL("GET", url, true, callHandle); } function callHandle(req) { Spry.Utils.setInnerHTML(div, req.xhRequest.responseText); } try this: var saveDivId; function callPage(url, div) { saveDivId = div; Spry.Utils.setInnerHTML(div, 'Loading...'); Spry.Utils.loadURL("GET", url, true, callHandle); } function callHandle(req) { // saveDivId used below instead of div Spry.Utils.setInnerHTML(saveDivId, req.xhRequest.responseText); } Quote Link to comment Share on other sites More sharing options...
CMellor Posted June 29, 2007 Author Share Posted June 29, 2007 Thank you! 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.