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
    Regular Coder
    Join Date
    Jul 2002
    Posts
    362
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Dynamic selection

    I am trying to get a drop down select where I make a selection of a last name it will populate the last name text box and a first name text box:

    If I have a selection of names such as this:

    Smith, Mark
    Jones, Rich
    Carson, Mike

    then when I select Jones, Rich it will populate my text boxes with Jones going into the Last Name text box and Mark going into the First name text box.

    Here is my attempt but not working:
    Code:
    function populateTxt2(txt) 
    {
    	if (txt.length > 0) 
    	{
           document.request.LastName.value = txt;
    	   document.request.FirstName.value = txt;
        }
    }
    
    
    <SELECT NAME="mySelect2" multiple="2" onchange="populateTxt2(this.options[this.selectedIndex].value);">
    			<OPTION VALUE=""></OPTION>
    			
    		
    			<OPTION VALUE="Smith,Rich">Smith,Rich</OPTION>
    <OPTION VALUE="Smith,Mark">Smith,Mark</OPTION>
    <OPTION VALUE="Jones,Rich">Jones,Rich</OPTION>
    <OPTION VALUE="Carson,Mike">Carson,Mike</OPTION>
    
    			</SELECT><br>
    First Name&nbsp;<input type="text" name="FirstName">
    Last Name&nbsp;<input type="text" name="LastName">
    Last edited by florida; 08-16-2005 at 06:32 PM.

  • #2
    New Coder
    Join Date
    Aug 2005
    Posts
    46
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is a page that teaches something very similar. It's called an autosuggest control. It works great. You start typing into a textbox and it shows a list of possible ways to complete it. You can populate the list of possible completions yourself. They can select one of the suggestions and it will automatically fill the textbox with it. You can read how they do that and pretty much the same principles will apply to what you're trying to do, but I'd suggest actually doing an autosuggest control. They work great. I have my own upgraded version that I work with (It's a little bit more advanced than the one they demonstrate, and I connected it to a database via asp.net to populate the possible suggestions)

    http://www.webreference.com/programm...mn2/index.html

  • #3
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,505
    Thanks
    3
    Thanked 501 Times in 488 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 language="JavaScript" type="text/javascript">
    <!--
    function populateTxt2(obj){
        txt=obj.options[obj.selectedIndex].value;
    	if (txt.length > 0)
    	{
           obj.form.LastName.value = txt.split(',')[0];
    	   obj.form.FirstName.value = txt.split(',')[1];
        }
    }
    
    //-->
    </script>
    
    <form name"request" >
    <SELECT NAME="mySelect2" multiple="2" onchange="populateTxt2(this);">
    <OPTION VALUE=""></OPTION>
    <OPTION VALUE="Smith,Rich">Smith,Rich</OPTION>
    <OPTION VALUE="Smith,Mark">Smith,Mark</OPTION>
    <OPTION VALUE="Jones,Rich">Jones,Rich</OPTION>
    <OPTION VALUE="Carson,Mike">Carson,Mike</OPTION>
    </SELECT>
    <br>
    First Name&nbsp;<input type="text" id="FirstName">
    Last Name&nbsp;<input type="text" id="LastName">
    </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
    •