A
A
Adil12013-11-23 16:22:53
JavaScript
Adil1, 2013-11-23 16:22:53

How in rails 4 and jquery to make sure that when you click on a text field, the desired radio button is automatically selected?

in general, there are two radio buttons, I want the button to be selected when clicking on the text field, now everything works only once, but when you click on the text field a second time after selecting another radio button, the desired radio button is not selected

<%= f.label "Я готов заплатить за работу" %>
            <%= f.text_field :price %>  
            <%= f.radio_button :price, true %>
            <%= f.radio_button :price, false %>
            <%= f.label "Пусть исполнитель сам предложит цену" %>

           <code lang="java">
 <script>
            $(document).ready(function(){
              $('#post_price_false').click(function(){
                $('#post_price').val(''); 
              });
              $('#post_price').click(function(){
                $('#post_price_false').attr('checked',false);
                $('#post_price_true').attr('checked',true);
              });
              
              });</script>
</code>

ты программист или не программист? помоги плиз

Answer the question

In order to leave comments, you need to log in

2 answer(s)
A
Adil1, 2013-11-23
@Adil1

It turns out stupidly it was necessary to change $('#post_price_false').attr('checked',false);to$('#post_price_false').prop('checked',false);

V
voleo, 2013-11-23
@voleo

Use lable no jQuery needed.
As an example

<div class="field">
    <%= f.label :autolyse %><br />
    <%= f.label :autolyse, "Yes", :value => "true"  %>
    <%= f.radio_button :autolyse, true %>
    <%= f.label :autolyse, "No", :value => "false" %>
    <%= f.radio_button :autolyse, false, :checked => true %>
</div>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question