Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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!

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Get value of slider without post

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

Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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.

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Get value of slider without post

I used the code you posted and it works:

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

Image

Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Get value of slider without post

Yes, I used a built in component.

Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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

Thanks. :)

maxkatz
Posts: 0
Joined: Fri Aug 13, 2010 3:24 pm

Get value of slider without post

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

Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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

Branden
Posts: 0
Joined: Sun Nov 03, 2013 12:10 am

Get value of slider without post

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.

Return to “Issues”