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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

change listbox

Status
Not open for further replies.

innu

Programmer
Jun 13, 2001
40
AT
Hi,

I have the following problem:

We have 2 listboxes and there we want to give the value from one listbox to the another. Also we want to delete and to order it in one listbox.

Has anyone done sth. like that?
 
I don't quite understand the question..
Also we want to delete and to order it in one listbox.
But I can start by helping you with the first.

The JavaScript method that you use to add a new item to a select list is...
Code:
document.formname.listname.options[n] = new Option("Text","Value")
Now, how you use that between the two depends on exactly what you're trying to do. Can you be a little more descriptive on your project.

ToddWW
 
here is what i have:

(i guess it was tleish's post, but don't remember egg-zactly)
Code:
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>
<!--
    // You create a new OPTION with
      var opt = new Option('text', 'value');

    // and insert it with
      var sel = document.formName.selectName;
      sel.options[sel.options.length] = opt;

    // at the end of the SELECT list. 
    // To insert into the middle move other options up e.g.
    function insertOptionAt (select, option, index) {
        for (var i = select.options.length; i > index; i--)
        select.options[i] = select.options[i - 1];
        select.options[index] = option;
    }
  
    // example call 
    insertOptionAt (document.formName.selectName, new Option('text', 'value'), 3);

    // You delete an OPTION simply be setting
    var sel = document.formName.selectName;
    sel.options[optionIndex] = null;
    
//-->
</SCRIPT>
Victor
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top