Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 436
Fabien Lebas Avatar asked Mar 08 '13 15:03

Fabien Lebas


1 Answers

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 !

like image 191
Fabien Lebas Avatar answered Oct 14 '22 14:10

Fabien Lebas