Chris
Chris

Reputation: 3698

jQuery update slider's value on text field change

I'm developing a rails project that updates the slider's value to that of the text-field on any-change (probably keydown or change event).

My _form.html.erb file:

<div id="my-slider" class="slider-input"></div>
<%= f.input :var_name, label: false, wrapper: :append do %>
<%= f.text_field :var_name, value: @controller_name.var_name,
    id: "var_name", class: 'my-border answer-single', data: {autonumeric: true, aPad: false} %>

And the js code for the keydown event for my-input element is this:

$("#var_name").keydown(function(){
    alert("hey");
    var value = this.value();
    $("#my-slider").slider('value', value);
});

This is a JSFiddle that displays only the alert with the keydown or change events, but doesn't change the slider.

The problem is that at my application, I only have an alert into the jQuery selector and it doesn't display even the alert.

Upvotes: 0

Views: 990

Answers (1)

Venkata Krishna
Venkata Krishna

Reputation: 15112

DEMO -> http://jsfiddle.net/MD3mX/1132/

Use keyup instead of change.

Also use this.value instead of this.value() .. No parentheses required

$("#my-input").keyup(function () {
    $("#slider").slider("value", this.value);
});

Upvotes: 1

Related Questions