Home > Coding > Jquery UI Slider problem (and solution)…

Jquery UI Slider problem (and solution)…

I was having a problem with the slider control where it would jump to to 100% position seemingly randomly. After much hacking around with the slider control source code I found that a certain test in the control was treating the new value I was passing in as a string instead of a number. The test was coming up true and the function was returning the max slider value instead of my new value (which was less than max so the test should have failed).

Anyway I found that if I multiplied the value I was passing in by 1 (one), javascript would then treat it as a number instead of a string and everything worked fine.

So my code now says:

pos=pos*1;                                           // force pos to be numeric

$( “#slider” ).slider( “value”, pos );       // Set new slider position

I guess that just because it ‘looks’ like a number does not mean it will be treated like one. Lesson learned!

Advertisements
Categories: Coding
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: