Forum: Ruby on Rails Form Help

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Kim (Guest)
on 2007-01-25 22:09
(Received via mailing list)
I want to hide elements of a form from users untill they click on a
radio button.  Any pointers?

Thanks in advance - K
Mark D. (Guest)
on 2007-01-25 22:27
How you are generating the radio buttons?
Kim (Guest)
on 2007-01-25 22:38
(Received via mailing list)
radio_button_tag -  since it is not associated with a model

On Jan 25, 12:27 pm, Mark D. <removed_email_address@domain.invalid>
Mark D. (Guest)
on 2007-01-25 22:41
Ok, can you just insert some javascript into the onclick method:

radio_button_tag 'foo', 'foo', false, :onclick =>
'show_hide_appropriate_layer()'
Kim (Guest)
on 2007-01-25 22:47
(Received via mailing list)
Yes .. but what does the show_hide function look like? Thats were I am
having trouble.

Thanks -K

On Jan 25, 12:41 pm, Mark D. <removed_email_address@domain.invalid>
Kim (Guest)
on 2007-01-25 23:15
(Received via mailing list)
This is what Ihave tried - still not working:

in .rhtml (a partial)


              <%= radio_button_tag 'save',1, checked = false, options =
{:onclick => 'show_hidden_div'}  %>
              <label for="saved_name" >Save To My Modules:</label>


            <div id = "save_module", style="display:none;">
              <label for="saved_name" >Save As:</label>
              <%= text_field 'mod', 'saved_name'  %>
            </div>

In application.js:

function show_hidden_div(){
  if (document.getElementById) {
   var save = form.save;
   if (save[0].checked) {
     document.getElementById("save_module").style.display = "block";
   }
  }
}
Mark D. (Guest)
on 2007-01-25 23:24
It's a bit rough but something like this should work ok:
--

<%= radio_button_tag 'radios', 'one', false,
    :onclick => 'toggle(this.value)' %>
<label for="one">One</label><br />

<%= radio_button_tag 'radios', 'two', false,
    :onclick => 'toggle(this.value)' %>
<label for="two">Two</label><br />

<%= radio_button_tag 'radios', 'three', false,
    :onclick => 'toggle(this.value)' %>
<label for="three">Three</label><br />

<%= radio_button_tag 'radios', 'four', false,
    :onclick => 'toggle(this.value)' %>
<label for="four">Four</label><br />


<div id="info_one" style="display: none;">Hello from info 1!</div>
<div id="info_two" style="display: none;">Hello from info 2!</div>
<div id="info_three" style="display: none;">Hello from info 3!</div>
<div id="info_four" style="display: none;">Hello from info 4!</div>


<script type="text/javascript">
  function toggle(value) {
    get_element_by_id('info_one').style.display = 'none';
    get_element_by_id('info_two').style.display = 'none';
    get_element_by_id('info_three').style.display = 'none';
    get_element_by_id('info_four').style.display = 'none';
    get_element_by_id('info_'+value).style.display = 'block';
  }
  function get_element_by_id(id) {
    return document.getElementById(id);
  }
</script>
Kim (Guest)
on 2007-01-25 23:48
(Received via mailing list)
I got it to work  - thanks :)

On Jan 25, 1:24 pm, Mark D. <removed_email_address@domain.invalid>
This topic is locked and can not be replied to.