Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Populating Select with Values from Textbox

    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'):
    Code:
    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.

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    10,968
    Thanks
    0
    Thanked 236 Times in 233 Posts
    Is this what you wanted?
    Code:
    function addToList()
    {
    	var f = document.forms[0];
    	f.listBox.options[f.listBox.options.length] = new Option(f.textBox.value, f.textBox.value);
    }

  • #3
    New Coder
    Join Date
    Aug 2003
    Location
    Singapore
    Posts
    94
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by glenngv
    Is this what you wanted?
    Code:
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •