I am firing the following event when a button is clicked... onclick="new Ajax.Updater(''div123'', ''/gotit.php'',{asynchronous:true, evalScripts:true }); return false;" It all works fine, but I now need to add in some form fields when the button is clicked. There are two form fields, ''email'' and ''zipcode'' which i want to submit to /gotit.php when the button is clicked.... I can''t figure out how to do it though... Do I want to change it to this: onclick="new Ajax.Updater(''div123'', ''/gotit.php''+ value, { ... }, {asynchronous:true, evalScripts:true }); return false;" Thanks for any help.... --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
A. Based on the use case you describe, it seems you may actually want the "onsubmit" event rather than "onclick" (Make sure your button is of type submit) B. If the form fields you''re wishing to add are the only other inputs in the form, you can collect them with Form.serialize(''idOfForm'', true); [1] Otherwise, do something like {email: $(''email'').value, zipcode: $(''zipcode).value} C. Pass the form fields to the ''parameters'' option. [2] [3] e.x.: new Ajax.Updater(''div123'', ''/gotit.php'', { method: ''get'', //default is ''post''; use whichever is most appropriate to your situation parameters: Form.serialize(''idOfForm'', true), asynchronous:true, // Default behavior. Not needed. evalScripts:true }); TAG 1. http://www.prototypejs.org/api/form#method-serialize 2. http://www.prototypejs.org/api/ajax/options 3. A side comment here to those responsible for documentation: The example Ajax.Request (at http://www.prototypejs.org/api/ajax/ request ) doesn''t use "parameters" but builds its request string manually. Perhaps a different/additional example would be useful. On Jul 6, 2007, at 8:53 AM, Scott Phillips wrote:> > I am firing the following event when a button is clicked... > > onclick="new Ajax.Updater(''div123'', ''/gotit.php'',{asynchronous:true, > evalScripts:true }); return false;" > > It all works fine, but I now need to add in some form fields when the > button is clicked. There are two form fields, ''email'' and ''zipcode'' > which i want to submit to /gotit.php when the button is clicked.... I > can''t figure out how to do it though... > > Do I want to change it to this: > > onclick="new Ajax.Updater(''div123'', ''/gotit.php''+ value, { ... }, > {asynchronous:true, evalScripts:true }); return false;" > > Thanks for any help.... > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Totally works thanks. One last question, when I do it onsubmit, is there some way to actually then prevent the form from being submitted? My goal is to avoid the page refresh... thanks! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
Hey Scott, I confess I haven''t followed your thread so far, but on your current question: Scott Phillips a écrit :> Totally works thanks. One last question, when I do it onsubmit, is > there some way to actually then prevent the form from being submitted? > My goal is to avoid the page refresh... thanks!If you bind the submit event for your form, your listener function gets passed the event object. Just call Event.stop on it! Example: -- HTML <form id="frmMain"...> ... </form> -- JS function handleForm(e) { // Your processing, then (or before it): Event.stop(e); } // At DOM/page load time: $(''frmMain'').observe(''submit'', handleForm); ''HTH -- Christophe Porteneuve a.k.a. TDD "[They] did not know it was impossible, so they did it." --Mark Twain Email: tdd-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
I use Return false; in the function. ______________________________________________________________________ Alex Duffield ❖ Principal ❖ InControl Solutions . http:// www.incontrolsolutions.com On 7-Jul-07, at 11:54 AM, Scott Phillips wrote:> > Totally works thanks. One last question, when I do it onsubmit, is > there some way to actually then prevent the form from being submitted? > My goal is to avoid the page refresh... thanks! > > > >--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---