Sorry, just realized: You're saying that 'searchForm' gets inserted in the 'search' div via "ruby http post" (or via doUpdate, I'm not sure which, but it doesn't matter). And you're calling addObservers from window.onload. Well yes, order matters. The thing has to exist in the DOM before you can retrieve and access it. You have no guarantee that any Ajax calls are going to have completed before window.onload is fired. That's what the onSuccess callback[1] is for.
[1] http://prototypejs.org/api/ajax/options HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jan 21, 11:42 pm, theG <[email protected]> wrote: > When I hardcode a form into a div and try to get a handle on it via $ > ('') it works. When I include the txt dynamically via an AJAX update() > it doesnt: > > ----------JS-------------------- > function doUpdate(id, url) { > new Ajax.Updater(id, url); > > } > > doUpdate('search', 'search'); > doUpdate('menu', 'menu'); > > function doSearch(event) { > new Ajax.Updater('menu', 'menu', { > parameters: { > txt: $('txt').value > } > }); > event.preventDefault(); > > } > > function addObservers() { > $('searchForm').observe('submit', doSearch); > > } > > Event.observe(window, 'load', addObservers); > > -----form HTML-------- > Search > <form method="post" id="searchForm" style="display: inline"> > <input type="text" name="txt" id="txt" size="20"/> > <input type="submit" name="btnSubmitSearch" id="btnSubmitSearch" > value="Go!"/> > </form> > > -----------HTML---------- > <body> > <div id="search"> <!-- stuff here either inserted via ruby ajax > post OR hardcoded --> > </div> > > <div id="menu"> > </div> > </body> > > ------------------ > Now I get $('searchForm') is null when i use doUpdate('search', > 'search'); - gets it via ruby http post > If however i comment out "doUpdate('search', 'search');" and instead > actually hardcode into the div > > I looked into defer() but it didn't help. > > Thanks --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Prototype & script.aculo.us" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---
