Forum: Ruby on Rails AJAX and radio buttons

Announcement (2017-05-07): is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see and for other Rails- und Ruby-related community platforms.
Szymon N. (Guest)
on 2006-02-17 22:58

How can i use ajax with radio buttons?

I have form with 2 radio buttons, which updates div with the value of
selected radio button. It worked correctly when i used submit button,
but when i removed it and used observers it didn't. When i press the
first button it displays its value, but when i press the second button
it displays new value for a moment (0.5s ?) and then suddenly changes to
the first value.
Is there a way to send values just on 'onclick' or 'onchange' events?

Here's my observer:

<%= observe_field("user_osoba",									:frequency => 0.5,
:update => "new_user_form",									:url => { :action => 'select_type',
:type => 'person' }) %>

and here's 'select_type' action:

  def select_type
    @type = params[:type] || ''
    if @type == 'person'
      render :text => @type
    elsif @type == 'company'
      render :text => @type
Szymon N. (Guest)
on 2006-02-19 13:06
I've simplified select_type action, but it still doesn't work:

def select_type
  render :text => request.raw_post

It behaves really strange - it works few times, then after clicking
another radio button the value disappears. I've tried it on IE6, FF 1.5
and Opera 8.51 and it didn't work correctly on any of these browsers.
This topic is locked and can not be replied to.