On 10/6/05, Haazmatt <haazmatt@gmail.com> wrote:> I'm trying to create a dynamic page with content that changes based on
the
> item selected in a collection_select form object. I want an image at the
> bottom of the page to change when you select an item from the pop-up list.
> How do I get the selected item (in a variable) without doing a submit of
the
> form?
Take a look in the API docs for ActionView::Helpers::JavaScriptHelper.
The form_remote_tag helper creates a form that is submitted through
an XMLHttpRequest. Then you could add an onchange handler to your
<select> element that submits the form.
Or, you could look at the Ajax.Updated generated by form_remote_tag
and bind that to your <select> element yourself. If you were to hack
on the Javascript yourself, the following quick and dirty example may
get you started.
<script type="text/javascript">
function changeImage() {
new Ajax.Updater('my_image_div',
'/my_controller/select_cool_image/'
+ $F('my_select'), {asynchronous:true, evalScripts:true});
}
Event.observe('my_select', 'change', changeImage);
changeImage();
</script>
- Rowan
--
Morality is usually taught by the immoral.
_______________________________________________
Rails mailing list
Rails-1W37MKcQCpIf0INCOvqR/iCwEArCW2h5@public.gmane.org
http://lists.rubyonrails.org/mailman/listinfo/rails