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

    Dynamic Dropdown Menus and Textboxes

    I'm trying to have it, so that when a user clicks on an item in the dropdown menu it will show up in a textbox next to it, and they will be able to select a second item from the text box and that will appear as well. They also should be able to type in the box as well.

    What I'm currently using is the same as http://www.felgall.com/jstip37.htm

    Which uses the code below.


    Thanks




    START OF CODE

    <script language="JavaScript" type="text/JavaScript">
    function addOptions(chosen) {
    var selbox = document.myform.opttwo;
    if (selbox.options[0].value == " ") {
    selbox.options.length = 0;
    }
    var fnd = 0;
    for (n=0;n<selbox.length;n++){
    if(selbox.options[n].text == chosen){
    fnd = 1;
    }}
    if (!fnd) selbox.options[selbox.options.length] = new Option(chosen, selbox.options.length);
    }

    function delOptions(chosen) {
    var selbox = document.myform.opttwo;
    if (selbox.options[0].value != " ") {
    nomatch = new Array();
    for (n=0;n<selbox.length;n++){
    if(selbox.options[n].text != chosen){
    nomatch[nomatch.length] = new Array(selbox.options[n].value, selbox.options[n].text);
    }}
    selbox.options.length = 0;
    if (nomatch.length == 0) {
    selbox.options[0]= new Option("Select entries from the list at left"," ");
    } else {
    for (n=0;n<nomatch.length;n++){
    selbox.options[n] = new Option(nomatch[n][1], nomatch[n] [0]);
    }}}}
    </script>


    <form name="myform">
    <div
    align="center">
    <select name="optone" size="1">
    <option value=" "
    selected="selected"> </option>
    <option value="First Choice">First
    Choice</option>
    <option value="Second Choice">Second
    Choice</option>
    <option value="Third Choice">Third
    Choice</option>
    </select>
    <select name="opttwo" size="1">
    <option value=" "
    selected="selected">Select entries from the list at
    left </option>
    </select>
    <br />
    &nbsp;<br />
    <input name="add" value="Add"
    onclick="addOptions(document.myform.optone.options[document.myform.optone.selectedIndex].text);"
    type="button" /> <input
    name="del" value="Remove"
    onclick="delOptions(document.myform.opttwo.options[document.myform.opttwo.selectedIndex].text);"
    type="button" /></div>
    </form>

    END OF CODE

    Edit to be more specific.
    Last edited by dudeman456; 06-03-2005 at 09:02 PM.

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    PHP 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 
    FillTB(obj,tb){
     
    document.getElementById(tb).value=obj.options[obj.selectedIndex].text;
    // or
    // document.getElementById(tb).value=obj.options[obj.selectedIndex].value;
    }
    //-->
    </script></head>

    <body>
    <select name="" size="1" onchange="FillTB(this,'TB1');" >
    <option value="1">One</option>
    <option value="2">Two</option>
    <option value="3">Three</option>
    <option value="4">Four</option>
    <option value="5">Five</option>
    <option value="6">Six</option>
    </select>
    <input id="TB1" size="10">
    </body>

    </html> 
    also see

    http://www.vicsjavascripts.org.uk/Fo...endium.htm#f15

  • #3
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is great, but I need the user to be able put info in the text box as well as be able to select another item that goes into the box.

    This script is alot farder than I was thanks.

  • #4
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    but I need the user to be able put info in the text box
    Dont understand you can still type in the text box

  • #5
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes, but as soon as the user attemps to make a second selection, it disappears, let say you want a "TWO" and since "EIGHT" is not on the list, type that in, and I just remembered I need a "FOUR", everything disappears.

  • #6
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,504
    Thanks
    3
    Thanked 501 Times in 488 Posts
    Do yo want Eight added to the Select List

    or Do you wat a record of every thing that is entered in the text box?

  • #7
    New to the CF scene
    Join Date
    Jun 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Yes I want a all that is selected.


  •  

    Posting Permissions

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