Page 1 of 2

Get value of slider without post

Posted: Mon Nov 04, 2013 5:27 pm
by Branden

I have several dynamically-generated sliders on a page, each one with a default value of "15". The a user clicks the "Submit" button, I'd like to capture the values of the sliders and save them in localstorage.

The problem I'm having: regardless of what the slider is set to, I can only seem capture the default value, not the actual value.

In the past, I could use a form/POST to get the actual value, but using forms doesn't seem to be possible here.

Is there a way to capture the values of these dynamically-generated sliders?

Thanks!


Get value of slider without post

Posted: Mon Nov 04, 2013 5:46 pm
by maxkatz

If you know the component name/id, you can use jQuery to read its value. You can also use the Appery.io JS (a wrapper for jQuery select) to get teh value: http://docs.appery.io/javascript-api/

For example:
code
Appery("component_name").val();
/code


Get value of slider without post

Posted: Mon Nov 04, 2013 6:08 pm
by Branden

I do know the component name/id, but jQuery is picking up the value specified as its default, not the actual value selected.

Here's HTML of the slider:

And here's the code I'm using to get the value:

init_val = $("#init_slider_"+index).val();

This always seems to return '15', per the default specified. If I do not specify a default, it always returns null.


Get value of slider without post

Posted: Mon Nov 04, 2013 6:24 pm
by maxkatz

I used the code you posted and it works:

code
alert ($('#Screen3_slider').val());
/code

Image


Get value of slider without post

Posted: Mon Nov 04, 2013 6:26 pm
by Branden

But are you using a built-in component, or is it a dynamically generated slider? I wonder if that is making the difference...


Get value of slider without post

Posted: Mon Nov 04, 2013 6:28 pm
by maxkatz

Yes, I used a built in component.


Get value of slider without post

Posted: Mon Nov 04, 2013 7:02 pm
by Branden

Yeah, that's probably the difference. Any idea how I could get the value from a dynamically generated slider?

Thanks. :)


Get value of slider without post

Posted: Mon Nov 04, 2013 7:09 pm
by maxkatz

I'm not sure..maybe some jQuery Mobile glitch. Did you check the code that's being generated?


Get value of slider without post

Posted: Mon Nov 04, 2013 7:10 pm
by Branden

Actually, no, I did not. I will take a look and post my findings.


Get value of slider without post

Posted: Mon Nov 04, 2013 9:57 pm
by Branden

The code looks okay. Or at least there's nothing glaring wrong, but take that with a grain of salt.

The problem is that jQuery isn't capturing the new value of the slider. Could this be an event-related issue? Do I need to do something to the data after the Submit click but before capturing the value?

This seems like such a straightforward situation. Pretty common. I must be missing something simple.