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 to the CF scene
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help with selecting one item from multiple list boxes

    I know this is probably insanely easy but I've spent hours searching these forums and others for a solution for this problem. I have a form with 3 list boxes and I want a user to be able to select only one item from only one list box. When the user selects an item the other list boxes are deselected so when the user will eventually submit the form it is only passing the variable from the last box selected.
    Please see example. Thanks for any help, advice you can provide.
    Code:
    <form name="form1" method="post" action="">
      <table width="32%"  border="0">
        <tr>
          <th height="26" scope="row"><div align="center">Fruit</div></th>
          <th scope="row"><div align="center">Vegetables</div></th>
          <th scope="row"><div align="center">Meat</div></th>
        </tr>
        <tr>
          <th scope="row"><div align="center">
            <select name="select1" size="3" id="select1">
                <option>Apples</option>
                <option>Pears</option>
                <option>Oranges</option>
            </select>
          </div></th>
          <th scope="row"><div align="center">
            <select name="select2" size="3" id="select2">
                <option>Carrots</option>
                <option>Sprouts</option>
                <option>Lettuce</option>
            </select>
          </div></th>
          <th scope="row"><div align="center">
            <select name="select3" size="3" id="select3">
                <option>Beef</option>
                <option>Chicken</option>
                <option>Fish</option>
            </select>
          </div></th>
        </tr>
      </table>  
      <p>  
    </form>

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,536
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <form name="form1" method="post" action="">
      <table width="32%"  border="0">
        <tr>
          <th height="26" scope="row"><div align="center">Fruit</div></th>
          <th scope="row"><div align="center">Vegetables</div></th>
          <th scope="row"><div align="center">Meat</div></th>
        </tr>
        <tr>
          <th scope="row"><div align="center">
            <select name="select1" size="3" id="select1" onchange="OneSelect(this,'select1','select2','select3');" >
                <option>Apples</option>
                <option>Pears</option>
                <option>Oranges</option>
            </select>
          </div></th>
          <th scope="row"><div align="center">
            <select name="select2" size="3" id="select2"  onchange="OneSelect(this,'select1','select2','select3');" >
                <option>Carrots</option>
                <option>Sprouts</option>
                <option>Lettuce</option>
            </select>
          </div></th>
          <th scope="row"><div align="center">
            <select name="select3" size="3" id="select3" onchange="OneSelect(this,'select1','select2','select3');" >
                <option>Beef</option>
                <option>Chicken</option>
                <option>Fish</option>
            </select>
          </div></th>
        </tr>
      </table>
      <p>
    </form>
    <script language="JavaScript" type="text/javascript">
    <!--
    
    function OneSelect(obj,id1,id2,id2){
     sel=OneSelect.arguments;
     for (i=1;i<sel.length;i++){
      if (document.getElementById(sel[i])!=obj){
       document.getElementById(sel[i]).setAttribute('disabled','disabled');
      }
     }
    }
    //-->
    </script>

  • #3
    New to the CF scene
    Join Date
    Oct 2005
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks
    Last edited by adamram; 10-24-2005 at 03:20 AM.


  •  

    Posting Permissions

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