Hi!
Hi all,
How can I update a div tag on the current page based on a select list?
<table>
<tr>
<td>
<%= select(:foo, :bar, %w/one two/) %>
<tr>
<td><div id='mydiv'>Some text</div>
</table>
I would to something like this:
In the view:
<%= select('client','seller_type',{"Zone" => "Z","Assigned" => "A"},
:selected => @client.seller_type) %> <br>
<br>
<%= observe_field 'client_seller_type',
:frequency => 1,
:update => 'seller_type',
:url => {:action => 'seller_type'},
:with => 'type' %>
<div id="seller_type">
<%= render :partial => 'seller_type' %>
</div>
And then I would have something like this in the controller
(client_controller.rb):
def seller_type
unless(@params[:type].blank?)
if(@params[:type] == "Z")
@type = "Z"
else
if(@params[:tipo] == "A")
@type="A"
end
end
end
if request.xml_http_request?
render :partial => 'seller_type'
end
end
and have this partial (_seller_type.rhtml):
<% unless @tipo == "A" %>
Assigned<br>
<% else %>
Zone<br>
<% end %>
Off course, this is based on an existing code that I have (wich is more
complex than shown here), but It tells you, more or less, how can you
implement this kind of stuff. Your case would be simplier.
Using the above example, I would like 'mydiv' to change to 'one' or
'two' whenever a selection is made.
Yep, that would require less code than the one I put here, but I think
the one I give is more general, and hopefully, more usefull.
Hope this helps,
Ildefonso Camargo