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
New Developer
Posts: 1
Registered: ‎07-15-2009
My Device: Not Specified

Javascript dynamic html select

I need to modify (add and remove) my html select options dynamically using javascript. I am using the 8900 simulator (version 4.6.1) and 9530 simulator (version 4.7.0) and could NOT get it to work on either of them. I have ENABLED javascript functions on both simulators and other javascript function works including XMLHttpRequest. I tried several different ways to add or remove options but none of them works. I appreciate it if anyone can give me a pointer on what I did wrong or any different way to make it works. My javascript function work on FireFox and IE but not BB simulators. Thanks in advance.

 

My javascript function,

To remove/clear options: 

var selectElement = document.getElementById('someHtmlSelectElement');

selectElement.options.length = 0;

or 
selectElement.remove(0); // no java script error but option not removed to select tag
or
selectElement.length = 0; 

 

To add option:

var selectElement = document.getElementById('someHtmlSelectElement');

var newOption = document.createElement('option');

newOption.text = 'option text';

newOption.value = 'option value'; 

selectElement.add(newOption, null) // no java script error but option not added to select tag