0

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>

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

@Prakadeessh, once rendered to the browser, remember it isn't Rails anymore. It's simply HTML. The rendered HTML becomes more important than the originating view.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.