Form Help


#1

I want to hide elements of a form from users untill they click on a
radio button. Any pointers?

Thanks in advance - K


#2

How you are generating the radio buttons?


#3

radio_button_tag - since it is not associated with a model

On Jan 25, 12:27 pm, Mark D. removed_email_address@domain.invalid


#4

Ok, can you just insert some javascript into the onclick method:

radio_button_tag ‘foo’, ‘foo’, false, :onclick =>
‘show_hide_appropriate_layer()’


#5

This is what Ihave tried - still not working:

in .rhtml (a partial)

          <%= radio_button_tag 'save',1, checked = false, options =

{:onclick => ‘show_hidden_div’} %>
Save To My Modules:

        <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”;
}
}
}


#6

It’s a bit rough but something like this should work ok:

<%= radio_button_tag ‘radios’, ‘one’, false,
:onclick => ‘toggle(this.value)’ %>
One

<%= radio_button_tag ‘radios’, ‘two’, false,
:onclick => ‘toggle(this.value)’ %>
Two

<%= radio_button_tag ‘radios’, ‘three’, false,
:onclick => ‘toggle(this.value)’ %>
Three

<%= radio_button_tag ‘radios’, ‘four’, false,
:onclick => ‘toggle(this.value)’ %>
Four

Hello from info 1!
Hello from info 2!
Hello from info 3!
Hello from info 4!

#7

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


#8

I got it to work - thanks :slight_smile:

On Jan 25, 1:24 pm, Mark D. removed_email_address@domain.invalid