...

View Full Version : Dynamic selection



florida
08-16-2005, 07:29 PM
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:


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">

Brett Bretterso
08-16-2005, 08:10 PM
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/programming/javascript/ncz/column2/index.html

vwphillips
08-16-2005, 09:25 PM
<!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>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum