Radio button onclick

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

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

<%= 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)

this is all untested!

jQuery is fantastic and has loads of really useful plugins - it’s really
essential.

good luck.

Max W. wrote:

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

<%= 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)

this is all untested!

jQuery is fantastic and has loads of really useful plugins - it’s really
essential.

good luck.

Oops., i forgot one important thing! The jQuery commands need to go
inside a ‘document ready’ block, which is run as soon as the page has
loaded. So, the script element should be:

oops again! and, of course, the script start tag should be

not just "". This must be a friday...i never could get the hang of fridays.

Thankx… Max W. for your helphul informatin…

still i am faceing some problem…the text field2 is not working with
the corrosponding radio button.
Even when i select the radio button2 then also text field2 also
disable & textfield 2 also enable…

my total code with javascript is …

<%# checked by default %>
<%= radio_button_tag “field”, 1, true, {:id => “button1”} %>
<%= text_field_tag :field1, “”, {:id => “field1”} %>

<%= radio_button_tag “field”, 2, false, {:id => “button2”} %>
<%# disabled by default %>
<%= text_field_tag :field2, “”, {:id => “field2”, :disabled => true}
%>

will tou plese hepl me to solv this problem…
thanking you

Soutom Soutom wrote:

Thankx… Max W. for your helphul informatin…

still i am faceing some problem…the text field2 is not working with
the corrosponding radio button.
Even when i select the radio button2 then also text field2 also
disable & textfield 2 also enable…

Would you mind opening the page source and copying the section with the
fields and radio buttons, and posting it up here?