Soutom Soutom wrote:
i am trying to do some thing with radio button.
my main tergate is that i have 2 radio button and 2 text field.
when i click on a radio button1, then the corrosponding text field say
text1 will b active, and another text field say text2 will b inactive.
and again when if we click on the other radio button2 then the
corrosponding text field say text2 will be active and text1 will b
inactive.......
NOTE : Basically i am very new in Ruby On Rails..so i cant do this.
if anyone kindly hepl me i will be very much thankful to him/her
have a look at jQuery, which is perfect for this sort of thing. You'll
need to know a little bit of javascript (syntax mainly) but that's
pretty much essential for web dev.
You could set up the html as follows (this is inside a form):
<%# checked by default %>
<%= radio_button_tag "field", 1, true, {:id => "button1"} %>
<%= text_field_tag :field1, "", {:id => "field1"} %>
<br/>
<%= radio_button_tag "field", 2, false, {:id => "button2"} %>
<%# disabled by default %>
<%= text_field_tag :field1, "", {:id => "field2", :disabled => true} %>
then, at the top of the page, you could have the following script
(obviously it will only work once you've installed jQuery)
<script>
//disable text_field 2 (and enable 1) when button 1 is clicked
jQuery("#button1:checked").each(function()
jQuery("#field2")[0].disabled = true;
jQuery("#field1")[0].disabled = false;
});
//and vice versa
jQuery("#button2:checked").each(function()
jQuery("#field1")[0].disabled = true;
jQuery("#field2")[0].disabled = false;
});
</script>
this is all untested!
jQuery is fantastic and has loads of really useful plugins - it's really
essential.
good luck.