Reputation: 41
I am building a rails app. I would like to access the radio_button value in Java Script(in document.getElementById). Below is the code snippet from the form.html.erb. Kindly let me know on how to access the same. I tried a lot of options. But nothing worked.
<div class="field">
<div class="container-fluid">
<div class="row">
<div class="col-md-6">
<div class="col-md-4">
<%= "Yet to start" %>
<%= radio_button("section", "1", "Tag1", :checked => true) %>
</div>
<div class="col-md-4">
<%= "In Progress" %>
<%= radio_button("section", "2", "Tag2") %>
</div>
<div class="col-md-4">
<%= "Completed" %>
<%= radio_button("section", "3", "Tag3") %>
</div>
</div>
</div>
</div>
</div>
Upvotes: 0
Views: 280
Reputation: 2009
Option 1: Inspect the outputted HTML. Get the ID and use it in javascript
Option 2: Specify the ID manually, like: <%= radio_button("development_activity", "progress", "Yet to start", :checked => true, :id => 'custom_id') %>
Upvotes: 1