Brainy Prb
Brainy Prb

Reputation: 433

Value from input element is not properly working in Jquery

Jsfiddle Link: https://jsfiddle.net/gzp0pcot/

I have an input element with id "myTextBox"

I want to change the slider value as I change the value in this input box. So I am using Jquery which triggers a function when anything is changed/pasted on that input box.

$("#ex1").slider('setValue',this.value);

Above statement should change the slider value and position. If I pass integer value directly, it works but it is not working for current input element value. Below statement works and changes slider position:

$("#ex1").slider('setValue',578);

Also current input element value is working if I use alert() function. And if I change the value of "val" variable manually, then also the slider changes its position but current value is not reflected.

I am using Bootstrap slider from : https://github.com/seiyria/bootstrap-slider

I also tried below statements to get current value , which I suppose are equivalent to above method I am using i.e. this.value :

var val = documentgetElementById("#myTextBox").value;
var val = $(this).val();
var val = $("$myTextBox").val();

But no luck with this too.

Upvotes: 0

Views: 36

Answers (1)

Mouser
Mouser

Reputation: 13304

Wrap this.value into parseInt to force it being viewed as an integer.

parseInt(this.value, 10);

updated fiddle: https://jsfiddle.net/gzp0pcot/3/

Upvotes: 3

Related Questions