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
Highlighted
Trusted Contributor
Posts: 202
Registered: ‎11-21-2010
My Device: 9700
My Carrier: Virgin Mobile
Accepted Solution

Add Items to Select

I can execute a SQLite select statement to return results.  How do I loop through the results using javascript to add items to a <select> in the form?  I can getelementbyyid but how do I add itemsfrom the results?

 

Trusted Contributor
Posts: 202
Registered: ‎11-21-2010
My Device: 9700
My Carrier: Virgin Mobile

Re: Add Items to Select

Is this something that can be done?  Does it need to go between <select></select>?

Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: Add Items to Select

this site has the code to add an item to the select. I found it by searching google...

 

http://www.mredkj.com/tutorials/tutorial005.html

_________________________________________
www.jasonmace.com/blackberry
Developer
Posts: 482
Registered: ‎10-24-2008
My Device: 9300
My Carrier: AT&T

Re: Add Items to Select

actually, I just checked and found a snippet where I was doing what you needed. Check the code below

 

 

tx.executeSql("SELECT name,prop,api FROM Well",[],
   function processLoadingWells(tx, rs) {
      for (var i=0; i < rs.rows.length; i++) {
         var elOptNew = document.createElement('option');
	 elOptNew.text = rs.rows.item(i)['name'];
	 elOptNew.value = rs.rows.item(i)['prop'];
	 var elSel = document.getElementById('wellSelect');
	 elSel.add(elOptNew, null);
      }
   },
   function() { alert('failure');}
);

 

 

_________________________________________
www.jasonmace.com/blackberry
Trusted Contributor
Posts: 202
Registered: ‎11-21-2010
My Device: 9700
My Carrier: Virgin Mobile

Re: Add Items to Select

Excellent.  Thank you very much.