Hello... New to prototype... I know this is probably just really
really simple but i have not been able to find a good tutorial
explination or documetation explination for how to do this... I Would
like this code to update the value of the cust_city form field...
thanks in advance for the help :o)
<CODE>
<script type="text/javascript"
src="../prototype.js"></script>
<script>
function checkZip() {
if($F(''cust_zipcode'').length == 5) {
var url = ''ajax.zip_code.php'';
var params = ''zip='' + $F(''cust_zipcode'');
var ajax = new Ajax.Updater(
{success: ''zipResult''},
url,
{method: ''post'', parameters: params, onFailure:
reportError}
);
}
}
function reportError(request) {
$F(''zipResult'') = "Error";
}
</script>
..
...
<input name="cust_zipcode" type="text"
id="cust_zipcode" tabindex="6"
size="13" onkeyup="checkZip();" />
<input name="cust_city" type="text"
id="cust_city" size="35" />
</CODE>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Since you''re using Ajax.updater and not Ajax.Request, you need to
supply the ID of the element you wish to update.
Typically the syntax is as follows:
new Ajax.Updater(el, url, { method: ''get'' });
el = ID of the element you''re updating. In your case, use something
like <input id=''city''>, so use ''city''
as your ID in your call
url = if you''re using GET you can pass the parameter in the URL, so in
your case the URL is:
''ajax.zip_code.php?zip='' +
$F(''cust_zipcode'');
You can add the error handing if you want to.
Giv it a try.
On Mar 24, 2:32 pm, Joey H
<cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Hello... New to prototype... I know this is probably just really
> really simple but i have not been able to find a good tutorial
> explination or documetation explination for how to do this... I Would
> like this code to update the value of the cust_city form field...
>
> thanks in advance for the help :o)
>
> <CODE>
>
> <script type="text/javascript"
src="../prototype.js"></script>
> <script>
> function checkZip() {
> if($F(''cust_zipcode'').length == 5) {
>
> var url = ''ajax.zip_code.php'';
> var params = ''zip='' +
$F(''cust_zipcode'');
>
> var ajax = new Ajax.Updater(
> {success:
''zipResult''},
> url,
> {method: ''post'',
parameters: params, onFailure: reportError}
> );
>
> }
> }
>
> function reportError(request) {
> $F(''zipResult'') =
"Error";
> }
> </script>
>
> ..
> ...
>
> <input name="cust_zipcode" type="text"
id="cust_zipcode" tabindex="6"
> size="13" onkeyup="checkZip();" />
>
> <input name="cust_city" type="text"
id="cust_city" size="35" />
>
> </
CODE>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
Hi Diodeus,
Can''t seem to get it to work correctly... I can get it to appear in a
div tag though, i know that it''s something simple that I am doing
wrong to make it show in a as the value of a text box.
Like this :
var url = ''ajax.zip_code.php'';
var params = ''zip='' +
$F(''cust_zipcode'');
var ajax = new
Ajax.Updater(''document.form1.cust_city.value'',
url, {method: ''post'', parameters: params}
or This
var url = ''ajax.zip_code.php'';
var params = ''zip='' +
$F(''cust_zipcode'');
var ajax = new Ajax.Updater(''cust_city'', url, {method:
''post'',
parameters: params}
Thanks, Joe
On Mar 24, 2:25 pm, Diodeus
<diod...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Since you''re using Ajax.updater and not Ajax.Request, you need to
> supply the ID of the element you wish to update.
>
> Typically the syntax is as follows:
>
> new Ajax.Updater(el, url, { method: ''get'' });
>
> el = ID of the element you''re updating. In your case, use
something
> like <input id=''city''>, so use
''city'' as your ID in your call
>
> url = if you''re using GET you can pass the parameter in the URL,
so in
> your case the URL is:
>
> ''ajax.zip_code.php?zip='' +
$F(''cust_zipcode'');
>
> You can add the error handing if you want to.
>
> Giv it a try.
>
> On Mar 24, 2:32 pm, Joey H
<cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Hello... New to prototype... I know this is probably just really
> > really simple but i have not been able to find a good tutorial
> > explination or documetation explination for how to do this... I Would
> > like this code to update the value of the cust_city form field...
>
> > thanks in advance for the help :o)
>
> > <CODE>
>
> > <script type="text/javascript"
src="../prototype.js"></script>
> > <script>
> > function checkZip() {
> > if($F(''cust_zipcode'').length == 5) {
>
> > var url =
''ajax.zip_code.php'';
> > var params = ''zip='' +
$F(''cust_zipcode'');
>
> > var ajax = new Ajax.Updater(
> > {success:
''zipResult''},
> > url,
> > {method:
''post'', parameters: params, onFailure: reportError}
> > );
>
> > }
> > }
>
> > function reportError(request) {
> > $F(''zipResult'') =
"Error";
> > }
> > </script>
>
> > ..
> > ...
>
> > <input name="cust_zipcode" type="text"
id="cust_zipcode" tabindex="6"
> > size="13" onkeyup="checkZip();" />
>
> > <input name="cust_city" type="text"
id="cust_city" size="35" />
>
> > </
>
> CODE>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
On Mon, Mar 24, 2008 at 12:32 PM, Joey H <cjharman-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I Would > like this code to update the value of the cust_city form field... > > var ajax = new Ajax.Updater( > {success: ''zipResult''}, > url, > {method: ''post'', parameters: params, onFailure: reportError} > );In order to update a form element''s value, you''ll need to use Ajax.Request, _not_ Ajax.Updater; the latter works on a DOM element''s contents, that is, the HTML elements inside another HTML element. The value of a form element, on the other hand, is set via its "value" attribute. So something more like this: new Ajax.Request(url, { method: ''post'', // not necessary (POST''s the default), but I''d use GET parameters: params, onSuccess: function(transport) { $(''cust_city'').value = transport.responseText; }, onFailure: reportError }); :Dan --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Duh!. Yup, Dan is right. On Mar 24, 4:06 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, Mar 24, 2008 at 12:32 PM, Joey H <cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I Would > > like this code to update the value of the cust_city form field... > > > var ajax = new Ajax.Updater( > > {success: ''zipResult''}, > > url, > > {method: ''post'', parameters: params, onFailure: reportError} > > ); > > In order to update a form element''s value, you''ll need to use > Ajax.Request, _not_ Ajax.Updater; the latter works on a DOM element''s > contents, that is, the HTML elements inside another HTML element. The > value of a form element, on the other hand, is set via its "value" > attribute. > > So something more like this: > > new Ajax.Request(url, { > method: ''post'', // not necessary (POST''s the default), but I''d use GET > parameters: params, > onSuccess: function(transport) { > $(''cust_city'').value = transport.responseText; > }, > onFailure: reportError > > }); > > :Dan--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Thanks Guys for the Help... I hope I can return the favor soon! Joe On Mar 24, 3:06 pm, "Dan Dorman" <dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Mon, Mar 24, 2008 at 12:32 PM, Joey H <cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > I Would > > like this code to update the value of the cust_city form field... > > > var ajax = new Ajax.Updater( > > {success: ''zipResult''}, > > url, > > {method: ''post'', parameters: params, onFailure: reportError} > > ); > > In order to update a form element''s value, you''ll need to use > Ajax.Request, _not_ Ajax.Updater; the latter works on a DOM element''s > contents, that is, the HTML elements inside another HTML element. The > value of a form element, on the other hand, is set via its "value" > attribute. > > So something more like this: > > new Ajax.Request(url, { > method: ''post'', // not necessary (POST''s the default), but I''d use GET > parameters: params, > onSuccess: function(transport) { > $(''cust_city'').value = transport.responseText; > }, > onFailure: reportError > > }); > > :Dan--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi guys,
Man, had to search for ages to find this solution :)
I would add that I couldn''t get the proposed solution to work using:
"onSuccess: function(transport) {
$(''cust_city'').value = transport.responseText;
}, "
After looking up the Prototype site and the Ajax.Request function
here: http://www.prototypejs.org/api/form/element/getValue I had to
adapt the onSuccess function to this:
onSuccess: function(transport) {
var frm = $(''formname'');
var room = frm[''room''];
$(room).value = transport.responseText;}
Small change, but caused a lot of frustration to find.
Cheers,
Ben.
On Mar 25, 6:44 am, Joey H
<cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Thanks Guys for the Help... I hope I can return the favor soon!
>
> Joe
>
> On Mar 24, 3:06 pm, "Dan Dorman"
<dan.dor...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > On Mon, Mar 24, 2008 at 12:32 PM, Joey H
<cjhar...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
> > > I Would
> > > like this code to update the value of the cust_city form
field...
>
> > > var ajax =newAjax.Updater(
> > > {success:
''zipResult''},
> > > url,
> > > {method:
''post'', parameters: params, onFailure: reportError}
> > > );
>
> > In order to update a form element''s value, you''ll
need to use
> > Ajax.Request, _not_ Ajax.Updater; the latter works on a DOM
element''s
> > contents, that is, the HTML elements inside another HTML element. The
> > value of a form element, on the other hand, is set via its
"value"
> > attribute.
>
> > So something more like this:
>
> >newAjax.Request(url, {
> > method: ''post'', // not necessary (POST''s
the default), but I''d use GET
> > parameters: params,
> > onSuccess: function(transport) {
> > $(''cust_city'').value = transport.responseText;
> > },
> > onFailure: reportError
>
> > });
>
> > :Dan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
$(''room'').setValue( transport.responseText ); should work
assuming the
element has the id ''room'' and its unique
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---