Fabien Lebas
Fabien Lebas

Reputation: 503

Get HTML5 range value in Ruby on Rails form

I am trying to change the standard Ruby on Rails form to let the user input a value with HTML5 range. I can't figure out how I should replace the standard "<%= f.text_field :W1 %>".

I have a slider :

<input class="slide" type="range" min="0" max="200" id="slider1">

Displaying value in :

<text id="W1">100</text>

Thanks to Ajax :

    $("#slider1").change(function () {                    
   var newValue = $('#slider1').val();
   $("#W1").html(newValue);
});

I can't find out where and how I should get the input value to set W1 ?

EDIT : HTML5 range is range_field form herlper in Ruby. I'm still searching for the right implementation of it so any help would be appreciated

Upvotes: 7

Views: 7290

Answers (2)

Fabien Lebas
Fabien Lebas

Reputation: 503

I have it ! I had to replace

<input class="slide" type="range" min="0" max="200" id="slider1">

by

<%= f.range_field :w1, :min=>0, :max=>200, :class=>"slide", :id=>"slider1"%>

Thanks to those who helped me !

Upvotes: 15

Hass
Hass

Reputation: 1636

$("#W1").val(newValue);

This should do it.

Upvotes: 0

Related Questions