Fábio Miranda, I am able to make it work by moving the java script code to window on ready event.. That way i see that now it only submit once.. Thanks for your help.
The only problem, i have similar onClick events in couple of web pages, and it is doing same thing, just remote URL is changed. that is only reason, i wanted to generalize the script as a function. For some reason onclick from a hyperlink event is creating issue if i add a onlcilck function in the jsp. praveen On Mar 19, 2:32 pm, Fábio M. Costa <[email protected]> wrote: > Its not super pretty but you can do this too: > > function processFormAjaxCall(remoteUrl, targetDiv, formId, method) { > alert("form submit" + remoteUrl + ":" + targetDiv); > var request = new Request.HTML({ > url: remoteUrl, > update: targetDiv, > method: method > }); > request.post($(formId)); //This code is executing more than > once > *return false;* > > } > > <a id="addAtty" href="#" class="addmore" > onclick="*return*processFormAjaxCall('addMoreItems.action', > 'resultList','frmId','POST' )"> > > returning false will do the same thing as the stop method. > > I would NOT recommend you to use this. You should always try to use > unobstrusive javascript. You shouldnt mix javascript into your html, thats a > bad practice. And you shoudnt be creating an instance of a request at each > user click. > > Theres no way around hardcoding the ids from the elements. Or you use a > richfaces kind of thing or youll have to harcode your ids. Thats my opnion > but maybe someone has a better solution. > > -- > Fábio Miranda Costa > Solucione Sistemas > Engenheiro de interfaces > > On Fri, Mar 19, 2010 at 3:18 PM, praveen <[email protected]> wrote: > > how to stop adding events?. I want to run only one time. is there any > > thing wrong i am doing? > > > On Mar 19, 1:54 pm, "Matthew Hazlett" <[email protected]> wrote: > > > That's easy, your code is adding the event each time. Each time the link > > is > > > clicked it adds a new copy of the event. > > > > The 4th time there will be 4 events.. etc > > > > -----Original Message----- > > > From: [email protected] > > > > [mailto:[email protected]] On Behalf Of praveen > > > Sent: Friday, March 19, 2010 1:44 PM > > > To: MooTools Users > > > Subject: [Moo] ajax submit issue > > > > Hi, I am submiting a form on click of hyperlink using ajax call. the > > > issue is, first time it works fine. Second time i click the link the > > > event is firing twice and submiting twice. 3rd time it submits 3 > > > times..and so on..I am not getting why it is happening. Here is the > > > hyperlink and its code.. Let me know where i am doing wrong. > > > > function processFormAjaxCall(remoteUrl, targetDiv, formId, > > method) { > > > alert("form submit" + remoteUrl + ":" + targetDiv); > > > var request = new Request.HTML({ > > > url: remoteUrl, > > > update: targetDiv, > > > method: method > > > }); > > > > $('addAtty').addEvent('click', function(event){ > > > if (event) { > > > event.stop(); > > > event.preventDefault(); > > > } > > > request.post($(formId)); //This code is executing > > more > > > than once > > > time as i keep clicking my hyperlink. > > > }); > > > } > > > > Hyperlink in my jsp look like this(like a normal link, but just > > > incase) > > > <a id="addAtty" href="#" class="addmore" > > > onclick="processFormAjaxCall('addMoreItems.action', > > > 'resultList','frmId','POST' )">Add More Items</a> > > > > I click the hyperlink id: "addAtty" to trigger the ajaxcall. Please > > > let me if some help me to figure out whats happening, is it a ajax > > > issue or something else. > > > > To unsubscribe from this group, send email to > > > mootools-users+unsubscribegooglegroups.com or reply to this email with > > the > > > words "REMOVE ME" as the subject. > > > To unsubscribe from this group, send email to mootools-users+ > > unsubscribegooglegroups.com or reply to this email with the words "REMOVE > > ME" as the subject. To unsubscribe from this group, send email to mootools-users+unsubscribegooglegroups.com or reply to this email with the words "REMOVE ME" as the subject.
