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

Thread: select box?

  1. #1
    Regular Coder
    Join Date
    May 2004
    Posts
    391
    Thanks
    76
    Thanked 0 Times in 0 Posts

    select box?

    How can I change a select list depending what a user types in a text box?
    I'm just trying to grab the first 10 charactors of the text field and see if they match a particular string and then change the select list if they do.

    <script>
    function selectOption(oTxt){
    var sel = oTxt.form.selName;
    if (oTxt.value.substring(0,9)== "1Z9R29A403"){

    //MAKE SELECT LIST CHANGE TO VALUE "01" WHICH IS UPS NEXT DAY
    }
    }
    </script>

    <form method="POST" onSubmit="return false" >
    <p><input type="text" name="id" size="20" onkeyup="selectOption(this)" onblur="selectOption(this)"></p>
    <p><select size="1" name="selName">
    <option value="01">UPS NEXT DAY</option>
    <option value="02">UPS SECOND DAY</option>
    <option value="03">UPS GROUND</option>
    <option value="" selected>Select One</option>
    </select></p>
    </form>
    Last edited by nikko50; 01-19-2006 at 05:56 PM.

  • #2
    Senior Coder A1ien51's Avatar
    Join Date
    Jun 2002
    Location
    Between DC and Baltimore In a Cave
    Posts
    2,717
    Thanks
    1
    Thanked 94 Times in 88 Posts
    whooops wrong thread
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body>
    
    <script>
    function selectOption(oTxt,sel){
     var sel=document.getElementById(sel)
     for (var zxc0=0;zxc0<sel.options.length;zxc0++){
      if (oTxt.value.toLowerCase()==sel.options[zxc0].text.substring(0,oTxt.value.length).toLowerCase()){
       sel.selectedIndex=zxc0;
       break;
      }
    
     }
    }
    </script>
    
    <form method="POST" onSubmit="return false" >
    <p><input type="text" name="id" size="20" onkeyup="selectOption(this,'selName')" onblur="selectOption(this,'selName')"></p>
    <p><select size="1" name="selName"  id="selName">
    <option value="01">UPS NEXT DAY</option>
    <option value="02">UPS SECOND DAY</option>
    <option value="03">UPS GROUND</option>
    <option value="" selected>Select One</option>
    </select></p>
    </form>
    </body>
    
    </html>


  •  

    Posting Permissions

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