Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Contributor
hb15
Posts: 14
Registered: ‎06-01-2013
My Device: BlackBerry Dev Alpha B
Accepted Solution

Facing problem in focus for selected option in html "Select"

[ Edited ]

Dear Team,

 

I have created one select options for creating dropdown menu let say on main.html page.

on that page I can able to select and it is also showing proper selected item.

 

<select data-bb-style="stretch" data-bb-label="Select Player:" id="customDropDown" onchange="setSelectedPlayer()" >
            <option value="0">Guest</option>
            <option value="1" >Player 1</option>
            <option value="2" >Player 2</option>
            <option value="3" >Player 3</option>
            <option value="4" >Player 4</option>
        </select>

 

 

I am storing currently selected item in some variable using setSelectedPlayer() function call.

This variable contain correct value for selected item.

 

Now the problem is that when I go to someother page using "pushscreen()" let say on setting page.

and then came back to again to "main.html" but now my dropdown contain defualt value as selected and NOT my selected item.

 

I have already tried to set selected option using following on page load.

 

document.getElementById('customDropDown').selectedIndex = selectedPlayer;

document.getElementById('customDropDown').setSelectedItem(2); = selectedPlayer;

document.getElementById('customDropDown').options[selectedPlayer].selected = true;

 

but focus is still on "defualt" option. Note that internally selected value is proper. I mean let say I have selected 2nd option then after coming back from "Setting" page, I am not again able to select 2nd option but focus is on default option.

 

Please help me I am really stuck for this little thing.

 

Hope to get reply soon.

 

Thanks.

 

BlackBerry Development Advisor
twindsor
Posts: 832
Registered: ‎07-15-2008
My Device: Passport
My Carrier: Bell

Re: Facing problem in focus for selected option in html "Select"

Use the setSelectedText method. This sample does a similar thing: https://github.com/blackberry/BB10-WebWorks-Samples/blob/master/Sensors/index.html#L53
Tim Windsor
Open Source Technical Lead
BlackBerry Development Advisor
oros
Posts: 1,557
Registered: ‎04-12-2010
My Device: BlackBerry Z10

Re: Facing problem in focus for selected option in html "Select"

Hello hb15, did Tim's suggestion help here? If so, can you please Accept his post as the solution for future visitors? If not, please let us know and we'll do our best to help.

Cheers!

Erik Oros | @WaterlooErik | eoros@blackberry.com | Developer Issue Tracker

If a reply has answered your question, please click Accept as Solution to help other visitors in the future.