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 5 of 5
  1. #1
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Adding values to a multi select list box

    My Scenario.....

    I have a page that contains an empty multi select list box (main page). On the main page is an add products link.
    When you click this link it opens a pop up window that display’s a list of products.

    I want to be able to click on multiple table row's (not tick a box) and have the row id's appear in the multi select box on the main page.

    Is this possible?

    Thanks in advance

  • #2
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    in main page:
    Code:
    function addOption(objTargetSel, text, value){
        objTargetSel.options[objTargetSel.length] = new Option(text, value);
    }
    in popup page:
    Code:
    function addOption(text, value){
        if (opener && !opener.closed){
            opener.addOption(opener.document.theFormName.theSelectName, text, value); 
        }
        else {
           alert("The parent window is closed.");
        }
    }
    ...
    <tr id="blah" onclick="addOption(this.id, this.id)">
    The addOption function in the main page is generic, you can use it in any select element. If you are only using it to only one select box, you can simplify it by removing the objTargetSel as parameter.
    Code:
    function addOption(text, value){
        var objTargetSel = document.theFormName.theSelectName;
        objTargetSel.options[objTargetSel.length] = new Option(text, value);
    }
    Then in the popup:
    Code:
    if (opener && !opener.closed){
        opener.addOption(text, value); 
    }
    ...
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________

  • #3
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You are a champion!

  • #4
    New to the CF scene
    Join Date
    Jun 2004
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    There's always more!

    How can I add a button that when pressed removes any selected items in the multi select box?

    Thanks!

  • #5
    Supreme Master coder! glenngv's Avatar
    Join Date
    Jun 2002
    Location
    Philippines
    Posts
    11,068
    Thanks
    0
    Thanked 256 Times in 252 Posts
    Just set the length property of the options array to 0.
    Code:
    function deleteAllOptions(){
        document.theFormName.theSelectName.options.length=0;
    }
    Ohh, I thought you want to delete all options..
    Ok, here's the real code:
    Code:
    function deleteSelectedOptions(){
        var s = document.theFormName.theSelectName;
        for (var i=s.options.length-1;i>=0;i--){
            if (s.options[i].selected){
                s.options[i] = null;
            }
        }
    }
    Last edited by glenngv; 06-11-2004 at 08:06 AM.
    Glenn
    ____________________________________

    My Blog
    Tower of Hanoi Android app (FREE!)
    Tower of Hanoi Leaderboard
    Samegame Facebook App
    vBulletin Plugins
    ____________________________________


  •  

    Posting Permissions

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