Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Setting a Select selected value

I have a select which I am constructing the option values and wish to set the displayed option, in the past I have used Appery('select name').val('My option'); then refresh the select. This no longer works with jquery1.9 the select displays a blank value! How would I achieve this in Jquery1.9?

Regards,
Joe

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

Setting a Select selected value

Hi Joe.

Please use code below:

pre

//You have to change "mobileselectmenu_10" with your select component name.
var yourSelect = Appery("mobileselectmenu_10");
yourSelect.val("default");
yourSelect.selectmenu('refresh', true);

/pre

Regards.

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Setting a Select selected value

Hi Yurii, I have tried the code without success! I have shared the project to a href="mailto:support@appery.io" rel="nofollow"support@appery.io/a, would you have a look, the 'Select' has the items added on the success event of of the JourneyList service.

I am also experiencing some unexpected behavior on the click event on the 'event_btn' click event where I am using comparison operators to check out which item is selected from the select, this is failing to find the correct selected value. Whilst the project is shared would you be able to look at this as well?

Regards,
Joe

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

Setting a Select selected value

Hi Joe,

I've checked your app. And saw following mistake in your code:

In following line of code you have some wrong character on the start of the value.

pre

dropDown&#46;append('<option value="?' + val + '"?' + text + '</option');

/pre

See details on the screen: http://prntscr.com/3vtkpn/direct

So to get your code work you need to delete this character from your code.

Use code below:

pre

dropDown&#46;append('<option value="' + val + '"?' + text + '</option');

/pre

Regards.

Joe Bohen
Posts: 0
Joined: Wed Nov 28, 2012 11:28 am

Setting a Select selected value

Hi Yurii, Yes thanks that is a zero width space character which caused no problems in jquery 1.8. Thanks for pointing this out.

Josiel Denardi6690187
Posts: 0
Joined: Mon Feb 24, 2014 9:23 pm

Setting a Select selected value

Where I put this code? Page Load, Page Show, where? Thank you.

Josiel Denardi6690187
Posts: 0
Joined: Mon Feb 24, 2014 9:23 pm

Setting a Select selected value

The code is:

var yourSelect = Appery("mobileselectmenu_10");
yourSelect.val("default");
yourSelect.selectmenu('refresh', true);

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

Setting a Select selected value

Hi Josiel,

You can run this code when you need to set default value to your select component.

If you need do it on page show - use "page show" event handler.

Also, make sure you have option with "default" value.

Regards.

Return to “Issues”