...

View Full Version : Populating Select with Values from Textbox



Kylena
01-19-2005, 04:49 AM
Hi,

I'm trying to populate an empty select list with values that users will enter from a number of textboxes.

The list would contain the delimiter ":" separating the values.

I haven't have the faintest clue on how to populate the listbox.

What I have is (button called 'Add'):

function addToList()
{
var f = document.forms[0];
for (i = 0; i < listBox.length; i++)
{
if (f.textBox.value != null)
f.listBox[i].value = f.textBox.value;
break;
}
}

I know the code is wrong, but I don't know how to modify it. :confused:

glenngv
01-19-2005, 07:04 AM
Is this what you wanted?

function addToList()
{
var f = document.forms[0];
f.listBox.options[f.listBox.options.length] = new Option(f.textBox.value, f.textBox.value);
}

Kylena
01-19-2005, 09:23 AM
Is this what you wanted?

function addToList()
{
var f = document.forms[0];
f.listBox.options[f.listBox.options.length] = new Option(f.textBox.value, f.textBox.value);
}

Thanks Glenn, I'll post back if I've any problems.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum