I have a modal dialog box which is containing search field. when I select element from drop down list, I got an error "element is null". Can not understand why did I get this error. Following is my code.
<%= label_tag :Search_by %>
<select name="search" id="search" >
<option value="0">Trainer</option>
<option value="1">Venue</option>
<option value="2">Country</option>
</select>
<div id="div_to_be_updated" style="float:right">
</div>
<%= observe_field 'search', :update => 'div_to_be_updated',:url => {:controller => 'events', :action=> 'pop_up_search' }, :with => "'is_delivery_address=' + escape(value)" %>
controller code::
def pop_up_search
@trainers= Trainer.all
@countries= Country.all
if ["0"].include?(params[:is_delivery_address])
render :partial => 'layouts/pop_up_trainer_search'
else
if ["1"].include?(params[:is_delivery_address])
render :partial => 'calendar/pop_up_venu_search'
else
render :partial => 'layouts/pop_up_country_search'
end
end
end
_pop_up_trainer_search.html.erb
<span style="text-align: right">
<% form_tag "/calendar/pop_up_trainer_view" do %>
<%= collection_select("event", "trainer_id", @trainers , :id, :name, {:prompt => true}) %>
<%= submit_tag "search" %>
<% end%>
</span>
Why did I get this error? Can anybody help me to correct this?
Suggestions:
check your JS in Firebug console
how does your form tag look like? do you have a :url set correctly?
is your :with parameter correct?
can you try to use symbols instead of strings when you reference DIVs? e.g. :search , :div_to_be_updated
<%= observe_field :search, :update => :div_to_be_updated,:url => {:controller => 'events', :action=> 'pop_up_search' }, :with => "'is_delivery_address=' + escape(value)" %>
how do your params look like, when you get the call to your pop_up_search()
does the DIV div_to_be_updated exist when you look in Firebug?
Sounds like your error is happening on the client, not at the server.
That means there's a problem with your JS.
That means that the observe_field
is not being turned into good JS.
Suggestions
Examine the source of your web page, as it is sent from the server.
Added Since it works when in the main erb, but not the popup erb, a couple of ideas:
search
id in the popups. It should be a unique dom element. Different ways to handle this, one is to hide, not destroy the popup.