Hi, Are those calls to doUpdate really inline? If so, they're probably happening before the DOM is ready. I'd suggest wrapping them in a dom:loaded event handler[1] or one of the other mechanisms for making sure the DOM is ready before trying to do things with it.
[1] http://prototypejs.org/api/document/observe HTH, -- T.J. Crowder tj / crowder software / com Independent Software Engineer, consulting services available On Jan 21, 11:42 pm, theG <gurpal2...@hotmail.com> 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 prototype-scriptaculous@googlegroups.com To unsubscribe from this group, send email to prototype-scriptaculous+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/prototype-scriptaculous?hl=en -~----------~----~----~----~------~----~------~--~---