Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Ruby and Ajax - dropdown menu to call action 1

Status
Not open for further replies.

jman78

Programmer
Jan 15, 2008
44
0
0
US
Hi -

I'm trying to implement a dropdown box with values of the previous bunch of years. That is completed. I want this dropdown to update a partial (list of db records). I've tried several times, and the closest I can get is that it reloads the entire page into the div I'm targeting. I've looked for tutorials on this subject, but all i can find are updating a small div with a separate db all or updating multiple dropdowns. Does anyone know where i can find a tutorial to create a dropdown box that renders a partial?

Thanks!
jason
 
I just made a huge step, now just have one small problem.

I have a dropdown box (id="selectedYear") that I need to retrieve the value of and send to an ajax call.

Here is the code snip. Can anyone tell me what I need to use to reference the value of the selected dropdown item?

Code:
<span class="bold">Select Year:
    <select id="selectYear">
      <% (1998..Time.now.year).to_a.reverse.each do |availYears| -%>
            <option value="<%= availYears -%>"><%= availYears -%></option>
      <% end %>
    </select>
    <%= observe_field ( :selectYear, :frequency => 0.25, :update => 'pr_body', :url => {:action => 'press_release_select', :year => @selectYear })  -%>
  </span>

Thanks again!

jason
 
completed!


View:
Code:
<span class="bold">Select Year:    <%= select_tag "selectYear", options_for_select([ "2008", "2007", "2006", "2005", "2004", "2003", "2002", "2001", "2000", "1999", "1998" ], "2007")  -%>  
    <%= observe_field ( :selectYear, :frequency => 0.25, :update => 'pr_body', :url => {:action => 'press_release_select'}, :with => 'selectYear' )  -%>
  </span>

Controller:
Code:
  def press_release_select
    @year = params[:selectYear]
    @press_releases = PressRelease.find(:all, :conditions => ["year(date) = ?", @year], :order => 'date desc')
    render :partial => "releases"
  end
 
Jason

I'm giving you a star because[ol][li]This Ruby forum doesn't get much action[/li][li]Nobody bothered to acknowledge your question[/li][li]You went ahead and posted the answer when you found it, just in case it helped someone else[/li][/ol]

Steve

[small]"Every program can be reduced by one instruction, and every program has at least one bug. Therefore, any program can be reduced to one instruction which doesn't work." (Object::perlDesignPatterns)[/small]
 
Well.. thanks =) Took me a bit of searching, but i figured it out. I can always hope that someone else has the same issues I have (...and that I can help relieve that!)

Jason
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top