# Ajax/Prototype/Scriptaculous

**URL:** <https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537>\
**Category:** Rails\
**Created:** [June 22, 2010, 11:38am UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537 "2010-06-22T11:38:34Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [June 22, 2010, 11:38am UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537/1 "2010-06-22T11:38:34Z")

</div>

Hello,

I can’t find a way to do what I’m trying so maybe someone can throw  
something at me.

The idea is if an option is not in a select list, the user can click a  
link  
next to the list ‘not there?’ and this will open uop a text field box  
below.  
The user then enters the missing option, hits enter and the select list  
will  
update and have the new entry already selected.

I can use remote\_form\_tag to get to send the text\_field without  
refreshing  
the page but I can’t find an option as with  
text\_field\_with\_auto\_complete’s  
:after\_update\_element. I want to fire another Ajax request to repopulate  
the  
select list.

I may already have seen the solution in my searching but I now can’t see  
the  
wood for the trees.

CIA

-ants

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [June 23, 2010, 12:47am UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537/2 "2010-06-23T00:47:48Z")

</div>

Perhaps you can add a link\_to\_remote, either in the section or  
surrounding it, to add an extra option then update the select list.

The Rails Cookbook has a section on using ajax to add DOM Elements to  
a page

And there is this :[http://api.rubyonrails.org/classes/ActionView/](http://api.rubyonrails.org/classes/ActionView/)  
Helpers/PrototypeHelper/JavaScriptGenerator/GeneratorMethods.html

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [June 23, 2010, 12:26pm UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537/3 "2010-06-23T12:26:06Z")

</div>

Yeah, thanks for that. I went away yesterday and when I came back to it,  
I  
arrived at the same solution.

Are you an expert with RJS? If so, I have another question. I have a  
select  
drop down list that will now be added to dynamically using RJS. But upon  
completion of the RJS request, all of my observer fields die (stop  
observing) unless I physically refresh the page.

Any idea what I need to do to rectify that?

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [June 23, 2010, 2:17pm UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537/4 "2010-06-23T14:17:20Z")

</div>

You need to re-add the observers in your RJS call. If you have an  
observer on an element with ID foo & you replace that element  
(page[:foo].reload), the observer goes with it. However, depending on  
how your observer is setup adding to the element ie another li or a  
subnode, can limit the need for resetting the observer.

JQuery has a “live” feature that basically does this for you, albeit  
with a small performance overhead.

Niels

---

<div class="post-metadata">

**Author:** ![Ants\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/6de8d8/32.png) [@Ants\_P](https://www.ruby-forum.com/u/Ants_P)\
**Post date:** [June 23, 2010, 2:22pm UTC](https://www.ruby-forum.com/t/ajax-prototype-scriptaculous/190537/5 "2010-06-23T14:22:01Z")

</div>

Good timing, just came to check my replies.

Thanks for the heads up on that, I’ll give it a go. I hate frontend  
development!! Whatever was wrong with static HTML?!! 😉
