Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PocketPC create new list item in a listbox?

Status
Not open for further replies.

xpblueScreenOfDeath

Programmer
Sep 1, 2004
87
How do I create a new list item in a listbox in javascript? I tried the follow but it doesn't work in Pocket PC IE.

Code:
list.options[list.options.length] = new Option('text', 'value');

and

Code:
list.options.add(new Option('text', 'value'));

 
I suppose you could try:
Code:
newOp = document.createElement("option");
newOp.appendChild(document.createTextNode("text"));
newOp.value = "value";
list.appendChild(newOp);

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 

You need to be running IE4 or above on the pocket PC to be able to access the options collection.

What version are you running?

Dan

 
Actually, I am running the IE that came with PocketPC 2003 handheld device. I thinking there probably isn't a way.
 
Nah, there's always a way...well...usually.

Why not try putting the select in a div, then literally rewriting the div with the new option included in the select:
Code:
function test(list)
{ 
old = list.innerHTML;
newOp = "<option value='value'>Text</option>";
document.getElementById("theDivID").innerHTML = "<select>"+old+newOp+"</select>";
}

hope that helps

"It is the mark of an educated mind to be able to entertain a thought without accepting it." - Aristotle
 
I tried already tried rewriting the div. The problem with rewrite the div is that the onchange event doesn't work when the listbox is created dynamically. Thanks elegidito for the suggestion anyways. Dan I'll have get back to with the version of IE because I am not at work right now.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top