I''m wondering as to how one can take input from a user (say through a text box) and update a database with it without having to use a form. How does the text entered get sent to a processing script? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Depends.. if you want to use an event like onChange then do something like: <input type="text" id="myinput" /> <script> function onChangeHandler(event){ var element = Event.element(event); yourFunction(element.value); } Event.observe(''myinput'',''change'',onChangeHandler); </script> If you want it sent when the user presses enter, I think you will need to use a form: <form id="myform"><input type="text" /></form> <script> function onSubmitHandler(event){ var form = Event.element(event); var element = Form.findFirstElement(form); yourFunction(element.value); } Event.observe(''myform'',''submit'',onSubmitHandler); </script> Is that what you wanted to know? Colin frank wrote:> I''m wondering as to how one can take input from a user (say through a > text box) and update a database with it without having to use a form. > How does the text entered get sent to a processing script? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
After some further reading, I''ve discovered that new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "processor_script", {paramName:"name"}); and $_POST[''name''] do the trick. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Maybe you were asking about the browser/server communication? <form action="javascript:;" onSubmit="new Ajax.Request(''myscript.php'',{parameters:From.serialize(this)});"> <textarea id="textareaid" name="user_text"></textarea> </form> ---------- server would get: POST: ''user_text'' => ''Whatever the user entered here'', ''_''=> No different than if the form was submitted using the usual action="myscript.php" other than the extra post variable ''_'' which has no value and is added by the Prototype Ajax. calls (to help distinguish Ajax requests from non-Ajax requests, I assume). That is using an inline for brevity but the same could be done with an event handler (see my previous email). Also could use something like parameters: ''myparamname=''+$(''textareaid'').value in the options for the Ajax.Request/Updater if you wanted to ditch the form (i.e. didn''t want/need to use onSubmit) There are many ways to do it, hope this helps. Colin frank wrote:> I''m wondering as to how one can take input from a user (say through a > text box) and update a database with it without having to use a form. > How does the text entered get sent to a processing script? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Ahh, you were asking about Autocompleter and php specifically.. frank wrote:> After some further reading, I''ve discovered that > > new Ajax.Autocompleter("autocomplete", "autocomplete_choices", > "processor_script", {paramName:"name"}); > > and $_POST[''name''] do the trick. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frank a écrit :> I''m wondering as to how one can take input from a user (say through a > text box) and update a database with it without having to use a form. > How does the text entered get sent to a processing script?As you''ve discovered, if you''re into autocompletion, there''s Ajax.Autocompleter. Otherwise, you''d just need to observe the field, either manually or through a Form.Element.EventObserver (which is better). Finally, remember that from a grammatical standpoint, <input> tags are only valid within <form> tags, even if those are not used by the UI eventually. -- 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 -~----------~----~----~----~------~----~------~--~---
Colin Mollenhour a écrit :> Maybe you were asking about the browser/server communication? > <form action="javascript:;" onSubmit="new > Ajax.Request(''myscript.php'',{parameters:From.serialize(this)});"> > <textarea id="textareaid" name="user_text"></textarea> > </form>The javascript: thing is 1,000 miles from any standard, and AFAIK, won''t work reliably on a couple browsers, I''m afraid. Why not just use an empty action, since you bind onsubmit? Also, in this example, there''s no way for the user to submit the form, is there? -- 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 -~----------~----~----~----~------~----~------~--~---
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta content="text/html;charset=ISO-8859-1" http-equiv="Content-Type"> </head> <body bgcolor="#ffffff" text="#000000"> Correct, no way to submit.. I realized that shortly after sending..<br> <br> I use the javascript:; thing because I''ve had problems before if the onSubmit code fails with an error, the page will try to submit the form to the current page. What exactly is your suggestion?<br> <form action=""> ???<br> <br> Thanks,<br> Colin<br> <br> Christophe Porteneuve wrote: <blockquote cite="mid45220214.5060801-x+CfDp/qHev2eFz/2MeuCQ@public.gmane.org" type="cite"> <pre wrap="">Colin Mollenhour a écrit : </pre> <blockquote type="cite"> <pre wrap="">Maybe you were asking about the browser/server communication? <form action=<a class="moz-txt-link-rfc2396E" href="javascript:;">"javascript:;"</a> onSubmit="new Ajax.Request(''myscript.php'',{parameters:From.serialize(this)});"> <textarea id="textareaid" name="user_text"></textarea> </form> </pre> </blockquote> <pre wrap=""><!----> The javascript: thing is 1,000 miles from any standard, and AFAIK, won''t work reliably on a couple browsers, I''m afraid. Why not just use an empty action, since you bind onsubmit? Also, in this example, there''s no way for the user to submit the form, is there? </pre> </blockquote> <br> --~--~---------~--~----~------------~-------~--~----~<br> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. <br> To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org <br> For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs <br> -~----------~----~----~----~------~----~------~--~---<br> </body> </html> <br>
Hey Collin, Colin Mollenhour a écrit :> Correct, no way to submit.. I realized that shortly after sending.. > > I use the javascript:; thing because I''ve had problems before if the > onSubmit code fails with an error, the page will try to submit the form > to the current page. What exactly is your suggestion? > <form action=""> ???AAMOF, yes, although this is inaccessible (progressive enhancement is way better, baby!). OR, you could use exception catching to avoid onsubmit''s event handler crashing down. You could also start your onsubmit handler code by "castrating" the event (Event.stop(e)) to make sure it won''t propagate, even if an error occurs (this to double-check, but I''m pretty sure it works). -- Christophe Porteneuve aka TDD 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 -~----------~----~----~----~------~----~------~--~---
Is there a way to send an extra parameter with Autocompleter? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You can always use the "callback" function in the options. Colin frank wrote:> Is there a way to send an extra parameter with Autocompleter? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frank a écrit :> Is there a way to send an extra parameter with Autocompleter?Sure: use the parameters options key if those are static (they will then always appear in addition to default/callback-provided params), or the callback options key to make those dynamic, as Colin says. The callback function takes two arguments: 1) the input element 2) the encoded current status of the parameters (paramName=uriEncodedToken) It returns the new parameter string. -- 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 -~----------~----~----~----~------~----~------~--~---
So what would it look like? new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "processor_script", {paramName:"name" callback(paramName:"name2")}); ? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Well if it is a fixed parameter just use: new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "processor_script", { paramName:"name", parameters:"param2=value2¶m3=value3" }); will result in "name=value¶m2=value2¶m3=value3" The callback is useful if you need parameters from some other element or want to build them your own way: Example: <h3>Search</h3> <form action=""> <select name="field"> <option value="name">Person</option> <option value="company_name">Company</option> <option value="person_notes">Notes</option> </select> <select name="position"> <option value="starts_with">starts with</option> <option value="contains">contains</option> </select> <input type="text" id="searchbox" class="autocomplete" name="searchstring"/> <span id="indicator" style="display: none"><img src="/images/indicator.gif" alt="Working..." /></span> <div id="autocomplete_choices" class="autocomplete"></div> </form> <div id="contact_details" style="display:none;"></div> <script type="text/javascript"> new Ajax.Autocompleter(''searchbox'',''autocomplete_choices'',''people.php'', { minChars: 2, frequency: 0.3, indicator: ''indicator'', select: ''field'', callback: function(element, entry){ var form = element.form; return Form.serialize(form); }, afterUpdateElement: function(field,element){ Element.show(''indicator''); new Ajax.Updater(''contact_details'',''people.php'',{ parameters:''id=''+element.id, onComplete: function(xhr,obj){ var container = $(''contact_details''); Element.hide(''indicator''); if(!Element.visible(container)) new Effect.SlideDown(container,{duration: 0.3}); } }); } }); $(''searchbox'').focus(); </script> frank wrote:> So what would it look like? > > new Ajax.Autocompleter("autocomplete", "autocomplete_choices", > "processor_script", {paramName:"name" callback(paramName:"name2")}); > > ? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I came up with this in the meantime... new Ajax.Autocompleter("autocomplete", "autocomplete_choices", "processor.php", {method:''post'',parameters:"value=value",paramName:"name"}); One more question. How would you take an input and then output something else? I know that Ajax.Updater can be used to retrieve some results and that, like above, Ajax.Autocompleter can be used to input it, but how do you orchestrate them? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
I don''t understand your question. Please make it easier on the people trying to help by phrasing your question precisely and in greater detail. Thanks, Colin frank wrote:> I came up with this in the meantime... > > new Ajax.Autocompleter("autocomplete", "autocomplete_choices", > "processor.php", > {method:''post'',parameters:"value=value",paramName:"name"}); > > One more question. How would you take an input and then output > something else? I know that Ajax.Updater can be used to retrieve some > results and that, like above, Ajax.Autocompleter can be used to input > it, but how do you orchestrate them? > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Here it is once again: Let''s say there''s a page with a textbox. You enter text into the textbox. As soon as you enter the text into the textbox, some information pertaining to the text you entered is displayed below the textbox. Some database queries might run in the backend which take the inputed text as paramters. I want to accomplish this withough having to press any buttons. Like I said, Ajax.Updater can perform most of the duties listed above, but I could only get Ajax.Autocompleter to send the text enter on the fly to a processing script. I do not know how to get the two to work together, or even if they are both required so that is why I am asking. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
It sounds like you don''t need Ajax.Autocompleter, it is overkill. However, looking at it''s code I came up with this in a matter of minutes. It''s not tested but you get the idea I think. If you need any more functionality that is included in Autocompleter but not here just look at the code (controls.js). Ajax.Listener = Class.create(); Ajax.Listener.prototype = { initialize: function(element,target,page,options){ this.element = $(element); this.target = $(target); this.page = page; this.options = Object.extend({ frequency: 1000, parameters: '''', ajaxOptions: {} },options || {} this.observer = null; this.onKeyPressHandler = onKeyPress.bind(this); Event.observe(this.element, ''keypress'', this.onKeyPressHandler); }, onKeyPress: function(){ if(this.observer) clearTimeout(this.observer); this.observer = setTimeout(this.onObserverEvent.bind(this), this.options.frequency*1000); }, onObserverEvent: function(){ var params = this.element.name+''=''+this.element.value; if(this.options.parameters) params += ''&''+this.options.parameters; new Ajax.Updater(this.target, this.page, Object.extend(this.options.ajaxOptions,{ parameters: params }); }, dispose: function(){ Event.stopObserving(this.element, ''keypress'', this.onKeyPressHandler); } } <textarea id="mytext" name="userText"></textarea> <div id="myinfoarea"></div> <script> new Ajax.Listener(''mytext'',''myinfoarea'',''mypage.php'',{ parameters: ''extraParam=extraValue'' }); </script> The POST on server side will be: ''userText'' => ''whatever they entered'', ''extraParam'' => ''extraValue'', ''_'' => '''' Colin frank wrote:> Here it is once again: > > Let''s say there''s a page with a textbox. You enter text into the > textbox. As soon as you enter the text into the textbox, some > information pertaining to the text you entered is displayed below the > textbox. Some database queries might run in the backend which take the > inputed text as paramters. I want to accomplish this withough having to > press any buttons. Like I said, Ajax.Updater can perform most of the > duties listed above, but I could only get Ajax.Autocompleter to send > the text enter on the fly to a processing script. I do not know how to > get the two to work together, or even if they are both required so that > is why I am asking. > > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frank a écrit :> I came up with this in the meantime... > > new Ajax.Autocompleter("autocomplete", "autocomplete_choices", > "processor.php", > {method:''post'',parameters:"value=value",paramName:"name"});You might want to post more realistic examples (or better-named params) than this one :-) But yeah, the idea''s here. You''ll end up, by default, with name=...&value=value.> One more question. How would you take an input and then output > something else? I know that Ajax.Updater can be used to retrieve some > results and that, like above, Ajax.Autocompleter can be used to input > it, but how do you orchestrate them?Collin''s full-fledged examples in a recent reply show an example of using A.A first and going A.U once a selection is made, using A.A''s afterUpdateElement option. -- 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 -~----------~----~----~----~------~----~------~--~---
Hey there, Collin''s solution is not without merit, but it needlessly duplicates a lot of s.a.us code. What you need to react to your in-field typing is either a Form.Element.EventObserver object (based on onchange) or a Form.Element.Observer (periodical value change check), both being provided by Prototype. Just hook up a small callback function of yours that will simply take the field''s value (2nd argument) and invoke a Ajax.Updater the usual way. Example: function fetchDataFromServer(elt, value) { new Ajax.Updater(''yourContentsContainer'', ''/your/url'', { parameters: ''yourServerField='' + encodeURIComponent(value) }); } // fetchDataFromServer new Form.Element.EventObserver(''yourInputId'', fetchDataFromServer); If you need time-based check for on-the-fly typing, use F.E.Observer instead, e.g. : new Form.Element.Observer(''yourInputId'', yourIntervalInSecs, fetch...); The interval can of course be floating-point, but I advise using one for a better overall user experience. -- Christophe Porteneuve aka TDD 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 -~----------~----~----~----~------~----~------~--~---
Wow, you''re right. I should''ve known Prototype had classes for similar stuff already.. That''s what happens when I''ve been up for 24hrs.. Btw dude, my name is spelled with one ''l'' no matter where you''re from. Just like your''s is Christophe and not Christopher :) Colin --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Colin, Colin Mollenhour a écrit :> Wow, you''re right. I should''ve known Prototype had classes for similar > stuff already.. That''s what happens when I''ve been up for 24hrs..I guess :-) It''s also not something you''d know if you haven''t looked at the code in depth (which I did for an upcoming book of mine), since there''s no centralized official doc for Prototype (despite Sergio''s best efforts), unlike s.a.us.> Btw dude, my name is spelled with one ''l'' no matter where you''re from. > Just like your''s is Christophe and not Christopher :)*bowing in apology*. Sorry about that, I think it''s the "ll" in your last name that popped into my head when writing your first name. -- Christophe Porteneuve aka TDD 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 -~----------~----~----~----~------~----~------~--~---
Thank you both for your responses. Christophe, It looks like it''s working but there''s one problem. The ''returngoeshere'' only updates after you click somewhere on the page instead of as soon as you finish typing. Here''s what it all looks like. <input type="text" id="textgoeshere"/> <div id="returngoeshere"></div> <script type="text/javascript"> function fetchDataFromServer(elt, value) { new Ajax.Updater(''returngoeshere'', ''processingfile'', { parameters: ''yourServerField='' + encodeURIComponent(value) }); } // fetchDataFromServer new Form.Element.EventObserver(''textgoeshere'', fetchDataFromServer); </script> The processingfile recieves the POST[''yourServerField''] variable and displays it. Also, shouldn''t Autocompleter do exactly what I''m after? According to the wiki, Autocompleter is to be used like so: new Ajax.Autocompleter(id_of_text_field, id_of_div_to_populate, url, options); So wouldn''t having just "textgoeshere" for id_of_text_field and "returngoeshere" for id_of_div_to_populate work? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Frank, You hold the title to Longest Thread Ever In This Group (28 posts with this one!). frank a écrit :> It looks like it''s working but there''s one problem. The > ''returngoeshere'' only updates after you click somewhere on the page > instead of as soon as you finish typing. Here''s what it all looks like.Yes, this is because you go Event-based, and onchange triggers on blur, basically. Try removing Event (Form.Element.Observer), as I mentioned at the bottom of my solution. You shouldn''t go too far below 1sec of interval, though. 1 sec is usually enough.> Also, shouldn''t Autocompleter do exactly what I''m after? According to > the wiki, Autocompleter is to be used like so:Actually no. Autocompleter is designed to provide a list of completions based on the current typing, not detailed info on the current text. Unless what you intend to return *is* completion options (with or without details), in which case, you don''t need Ajax.Updater at all, just Ajax.Autocompleter. However, you must then go with its flow (return a ul/li structure, possibly use rich li contents with "informal"-class''d elements, etc.). -- 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 -~----------~----~----~----~------~----~------~--~---
Thank you for your help. One last question. How would you trigger the fetchDataFromServer function with a button? So basically the text entered only gets sent to the processing script once a ''submit'' button is pressed. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
frank a écrit :> Thank you for your help. One last question. How would you trigger the > fetchDataFromServer function with a button? So basically the text > entered only gets sent to the processing script once a ''submit'' button > is pressed.If the button is a <input type="submit"/> in your form, just observe the form''s submit event: Event.observe(''yourFormId'', ''submit'', fetchDataFromServer); -- 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 -~----------~----~----~----~------~----~------~--~---
It doesn''t appear to be working. Event.observe(''formid'', ''submit'', fetchDataFromServer); <form id="formid"> <input type="text" id="textgoeshere"/> <input type="submit" value="submit"/> </form> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Frank, frank a écrit :> It doesn''t appear to be working. > > Event.observe(''formid'', ''submit'', fetchDataFromServer); > > <form id="formid"> > <input type="text" id="textgoeshere"/> > <input type="submit" value="submit"/> > </form>You *do* run the observe call *after* the DOM is loaded, right? -- 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 -~----------~----~----~----~------~----~------~--~---
Yes. If the script works then the problem must be on my end... --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hmm. I played around with it some more and I still couldn''t get it to work. Here''s what it looks like: <form id="formid"> <input type="text" id="textgoeshere"/> <input type="submit" value="submit"/> </form> <div id="returngoeshere"></div> <script type="text/javascript"> function fetchDataFromServer(elt, value) { new Ajax.Updater(''returngoeshere'', ''processing script'', { parameters: ''yourServerField='' + encodeURIComponent(value) }); } Event.observe(''formid'', ''submit'', fetchDataFromServer); </script> Whenever I click the submit button it reloads the page. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hey Frank, frank a écrit :> <form id="formid"> > <input type="text" id="textgoeshere"/> > <input type="submit" value="submit"/> > </form> > > <div id="returngoeshere"></div> > > <script type="text/javascript"> > > function fetchDataFromServer(elt, value) { > new Ajax.Updater(''returngoeshere'', ''processing script'', { > parameters: ''yourServerField='' + encodeURIComponent(value) > }); > > }What''s with "elt, value"?! Where do *those* come from? An event handler only gets the event as an argument. Here''s your code: function fetchDataFromServer(event) { Event.stop(event); var value = $F(''textgoeshere''); new Ajax.Updater(''returngoeshere'', ''processing script'', { parameters: ''yourServerField='' + encodeURIComponent(value) }); } ''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 -~----------~----~----~----~------~----~------~--~---
Christophe, Thank you. By the way, elt and value came form the function you posted earlier. function fetchDataFromServer(elt, value) { new Ajax.Updater(''returngoeshere'', ''processingfile'', { parameters: ''yourServerField='' + encodeURIComponent(value) }); } // fetchDataFromServer --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---