SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Addict next2heaven's Avatar
    Join Date
    Apr 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question How do I select all items in a listbox before posting?

    I have a form that allows the user to add items from one listbox to another listbox. When they click on submit, it needs to take all the items in the second list and post them to the next page. How do I select all listbox items before submitting?

  2. #2
    SitePoint Wizard
    Join Date
    Nov 2004
    Location
    Portsmouth UK
    Posts
    1,499
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    use a hidden textbox to hold the values and then process the values sside
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function ColectSel(selid,tbid){
     var sel=document.getElementById(selid);
     var tb=document.getElementById(tbid);
     tb.value='';
     for (var zxc0=0;zxc0<sel.options.length;zxc0++){
      tb.value+=sel.options[zxc0].value+',';
     }
    }
    
    //-->
    </script></head>
    
    <body>
    <select id="tom" >
    <option value="A" >AAAAAAA</option>
    <option value="B" >BBBBBBB</option>
    <option value="C" >CCCCCCC</option>
    <option value="D" >DDDDDDD</option>
    </select>
    <input id="fred" value="normally hidden" >
    <input type="button" value="TEST" onclick="ColectSel('tom','fred');" >
    </body>
    
    </html>

  3. #3
    SitePoint Evangelist SpaceFrog's Avatar
    Join Date
    Jan 2005
    Location
    Outerspace
    Posts
    511
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    set the second listbox to multiple and in the onsubmit event of your form loop on second select's option to set them all to selected

  4. #4
    SitePoint Addict next2heaven's Avatar
    Join Date
    Apr 2005
    Posts
    257
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    nice! Thanks!


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
  •