Radio buttons generated with rails radio_button not changing when clicked

sebkkom

I have the following code in categories.html.erb:

<%= form_for(@marker) do |f| %>
  <div> <%= f.radio_button("category", "1") %><label>Category 1</label> </div>
  <div> <%= f.radio_button("category", "2") %><label>Category 2</label> </div>
  <div> <%= f.radio_button("category", "3") %><label>Category 3</label> </div>
<% end %>

and the following javascript code in categories.js:

var update = function() {
  return console.log("Category Selected");
};

$("input[type='radio']").change(update);

The radio buttons never seem to get changed (nothing shows on my console log when I click a radio button).

What I originally want to do is to have a subcategory div inside every category one that will only show when the respective radio button is selected (and hide when another button is clicked).

UPDATE: I got this working with the following code:

$(document).ready(function(){
    $("input[type=radio]").change(function(){
      $(".subcategory").hide();
      $("#" + $(this).val()).show();
    });
});

Not sure why I had to put the code inside .ready though, to be honest. :$

sebkkom

I got this working with the following code:

$(document).ready(function(){
  $("input[type=radio]").change(function(){
    $(".subcategory").hide();
    $("#" + $(this).val()).show();
  });
});

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Radio buttons generated with rails radio_button not changing when clicked

From Dev

changing the value of a variable when a radio button is clicked

From Dev

How to check if any of the Radio buttons are checked or not when clicked on submit button

From Dev

jQueryMobile radio buttons when clicked generates errors

From Dev

Calculation of Inputted Values When Radio Buttons Are Clicked

From Dev

Rails place radio_button and label in the same row

From Dev

ng-model never populated when radio button (generated by ng-repeat) is clicked

From Dev

ng-model never populated when radio button (generated by ng-repeat) is clicked

From Dev

Dropdown not disable when radio button is clicked

From Dev

Make radio button stay highlighted when clicked

From Dev

Javascript radio button not copying fields when clicked

From Dev

highlight image when clicked on then check a radio button

From Dev

hide / show option when radio button is clicked

From Dev

jQuery on() does not fire on a dynamically generated / clicked radio button

From Dev

Rails radio buttons checked with params

From Dev

Rails multiple radio buttons not independent

From Dev

rails radio buttons choose available

From Dev

getting multiple radio buttons in rails

From Dev

Changing text when clicking radio button

From Java

How do you find the radio buttons not clicked?

From Dev

Preventing radio buttons from being clicked completely

From Dev

Detecting change in dynamically generated radio buttons with jQuery

From Dev

JS: Radio buttons - dynamically generated based on selection

From Dev

How to set the first child element's radio_button checked in rails4?

From Dev

changing the Style of Radio buttons in jQuery mobile 1.4.0

From Dev

Radio buttons, changing the background color PHP

From Dev

Radio button clicked with label

From Dev

Django Size (Dropdown) and Color (Radio Buttons) with changing prices/images dependant of radio button data JQuery

From Dev

Django Size (Dropdown) and Color (Radio Buttons) with changing prices/images dependant of radio button data JQuery

Related Related

  1. 1

    Radio buttons generated with rails radio_button not changing when clicked

  2. 2

    changing the value of a variable when a radio button is clicked

  3. 3

    How to check if any of the Radio buttons are checked or not when clicked on submit button

  4. 4

    jQueryMobile radio buttons when clicked generates errors

  5. 5

    Calculation of Inputted Values When Radio Buttons Are Clicked

  6. 6

    Rails place radio_button and label in the same row

  7. 7

    ng-model never populated when radio button (generated by ng-repeat) is clicked

  8. 8

    ng-model never populated when radio button (generated by ng-repeat) is clicked

  9. 9

    Dropdown not disable when radio button is clicked

  10. 10

    Make radio button stay highlighted when clicked

  11. 11

    Javascript radio button not copying fields when clicked

  12. 12

    highlight image when clicked on then check a radio button

  13. 13

    hide / show option when radio button is clicked

  14. 14

    jQuery on() does not fire on a dynamically generated / clicked radio button

  15. 15

    Rails radio buttons checked with params

  16. 16

    Rails multiple radio buttons not independent

  17. 17

    rails radio buttons choose available

  18. 18

    getting multiple radio buttons in rails

  19. 19

    Changing text when clicking radio button

  20. 20

    How do you find the radio buttons not clicked?

  21. 21

    Preventing radio buttons from being clicked completely

  22. 22

    Detecting change in dynamically generated radio buttons with jQuery

  23. 23

    JS: Radio buttons - dynamically generated based on selection

  24. 24

    How to set the first child element's radio_button checked in rails4?

  25. 25

    changing the Style of Radio buttons in jQuery mobile 1.4.0

  26. 26

    Radio buttons, changing the background color PHP

  27. 27

    Radio button clicked with label

  28. 28

    Django Size (Dropdown) and Color (Radio Buttons) with changing prices/images dependant of radio button data JQuery

  29. 29

    Django Size (Dropdown) and Color (Radio Buttons) with changing prices/images dependant of radio button data JQuery

HotTag

Archive