I have a range_field that allows a user to select between 0 and 100 in a form. I want to be able to show the value of the range_field, but am lost on how to do it. I am very new to rails and javascript so any help would be appreciated.
Thanks
I wouldn't use Javascript, honestly. I use the stock rails range_field in my application. You can check it out here:
Here is an example code snippet for a range field in my application:
<%= range_field :thing1, :in => 0..100, :step => '.1' %>
This makes a nice little slider that works well on iOS and web and looks okay on Android.
This snippet will let you update the label's value whenever the slider changes (or you could change the .change to .ready if you wanted to display it when the page loaded).
In the form
#form.html.erb
<%= form_for Foobar.new do |f| %>
<%= f.label :some_size, "Current Value = " %>
<%= f.range_field :some_size, :in => 0..100, :step => 1 %>
<% end %>
and then the jQuery
#form.js
$("#new_foobar").change(function() {
$form = $(this);
$input_value = $form.children("#foobar_some_size").val();
$label = $form.children("#foobar_some_size").siblings("label");
$label.text("Current Value = " + $input_value);
})