Topic: radio buttons + <div> not working properly

<h1>NEW CONTACT </h1>

<% form_for(@contact) do |f| %>
  <%= f.error_messages %>
  <p>
    <%= f.label :firstname %><br />
    <%= f.text_field :firstname %>
  </p>
  <p>
    <%= f.label :lastname %><br />
    <%= f.text_field :lastname %>
  </p>
  <p>
    <%= f.label :position %><br />
    <%= f.text_field :position %>
  </p>
  <p>
    <%= f.label :phone %><br />
    <%= f.text_field :phone %>
  </p>
  <p>
    <%= f.label :email %><br />
    <%= f.text_field :email %>
  </p>
  <br />
  <p>
<%= f.radio_button :employer_type, "customer", :checked =>true,
:onclick =>"Element.show('customerdiv');Element.hide('vendordiv');Element.hide('supplierdiv');"%></p>
<div id="customerdiv">
  <p>
     <%= f.collection_select :employer_id, Customer.find(:all), :id, :company, { :include_blank => true}, html_options={} %>
     <%= f.hidden_field(:employer_type, {:value => "customer"}) %>
  </p>
</div>
<p><%= f.radio_button :employer_type, "vendor", :checked =>false,
:onclick =>"Element.hide('customerdiv');Element.show('vendordiv');Element.hide('supplierdiv');"%></p>

<div id="vendordiv">
  <p>
     <%= f.collection_select :employer_id, Vendor.find(:all), :id, :company, { :include_blank => true}, html_options={} %>
     <%= f.hidden_field(:employer_type, {:value => "vendor"}) %>
  </p>
</div>
<p><%= f.radio_button :employer_type, "supplier", :checked =>false, :onclick => "Element.hide('customerdiv');Element.hide('vendordiv');Element.show('supplierdiv');"%></p>
<div id="supplierdiv">
  <p>
     <%= f.collection_select :employer_id, Supplier.find(:all), :id, :company, { :include_blank => true}, html_options={} %>
     <%= f.hidden_field(:employer_type, {:value => "supplier"}) %>
  </p>
</div>

  <%= f.submit "Submit" %>
  <%  end %>




<%= link_to 'Back', contacts_path %>


for some reason on the initial view of the page all 3 <div> show up, I've tried a few different changes none change it, so I am looking for some help DESPERATELY smile
after any radio button is clicked, it works at I thought it would, showing only 1 div at a time
I know there was a bug that I read about regarding radio buttons not working properly but I thought that was fixed up

Last edited by rblunt (2009-01-10 02:03:24)