SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    SitePoint Evangelist Tapan's Avatar
    Join Date
    May 2005
    Location
    India
    Posts
    564
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Question How to populate a combobox ?

    Hi,

    I have a combobox with a lot of values. I want a simple system in which i will provide a text box undernethe the combobox and if user types anything in that textbox...and if it matches the values in combobox then that should get selected in combobox.

    For example the combobox has following values:

    Apple
    Orange
    Grapes


    And now in textbox:

    As i type: Orange it should get selected above in combo box. Is that possible..?

    Thanks.

  2. #2
    SitePoint Addict richtestani's Avatar
    Join Date
    Nov 2003
    Location
    Bridgeport
    Posts
    292
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi,
    This is possible. Are your values pre-defined or will they be searched in a database?
    The simple way is to setup an array

    Code:
    var mylist = array('apples', 'oranges', 'pear', 'graprefruit');
    get the value of your text field.

    Code:
    var textField = document.getElementById('mytext').value;
    then cycle through them, and create nodes along the way and append them.

    Code:
    var selectList =document.getElementById('myselect');
    for(i=0; i<mylist.length; i++) {
    if(textField == mylist[i]) {
    var optionItem = document.createElement('option');
    var myValues = mylist[i];
    optionItem.value= myValues;
    var textItem = document.createTextNode(optionItem[0]);
    selectList.appendChild(optionItem);
    optionItem.appendChild(myValues);
    }
    I haven't tested this, but I did something similar to this and this is roughtly the code.
    RichTestani
    -------------------------------
    http://www.junkdepot.com
    http://www.rareoopdvds.com | The Movie Poster Site


Bookmarks

Posting Permissions

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