KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Setting the Chosen Option from a Select Box from Local Variable

I've currently got a select box named selectGameDates on a page who's options are loaded from a JSON call. When an option is selected, I store the value in a local storage variable called gameDate. I then reload the page and pass that new date into the JSON service. This all works fine except that I can't figure out how to get the chosen option to be the selected option when the page refreshes. Currently I'm trying to select the correct option by running this JS on the page load:

Appery("selectGameDates").val(localStorage.gameDate);
Appery("selectGameDates").selectmenu('refresh');

Any ideas?

KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Setting the Chosen Option from a Select Box from Local Variable

After playing around with it some more, If I change the JS script to run on scroll instead of load, it works just fine. Any ideas why it's not running on load?

KorryRogers
Posts: 0
Joined: Fri Aug 15, 2014 2:53 am

Setting the Chosen Option from a Select Box from Local Variable

Well, I got it working by adding the JS to the run on the success of the service call. I'd still like to know why it didn't work on the page load though. Thoughts?

Illya Stepanov
Posts: 0
Joined: Mon Mar 18, 2013 8:48 am

Setting the Chosen Option from a Select Box from Local Variable

Hi Korry,

It's doesn't work on page load event, because DOM elements are not shown and you can't read the state of elements on the page.

Yurii Orishchuk
Posts: 0
Joined: Fri Feb 14, 2014 8:20 am

Setting the Chosen Option from a Select Box from Local Variable

Hi Korry,

You can select current value only when component populated with data.

So in your case it "success" event handler(cause of the service populates the select).

This it's right way to use "success" event for your goal.

Regards.

Return to “Issues”