Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Dropdown Menu - populate textbox with different value

Status
Not open for further replies.

Jay319

Technical User
Feb 21, 2003
16
US
Hi,

I have a dropdown menu which when an account is selected I would like to have a textbox automatically populate with the account number.

Here is what I have started ...

<script language="javascript">
function MoveacctNumber()
{
var myVar = document.form1.acctNumber.value;
document.form1.txtID.value = myVar;
}
</script>
</head>

<body>
<form name="form1">
<select name="acctNumber" id="select" OnChange="MoveacctNumber()">
<%
While (NOT rstest.EOF)
%>
<option value="<%=(rstest.Fields.Item("acctName").Value)%>" <%If (Not isNull((rstest.Fields.Item("acctName").Value))) Then If (CStr(rstest.Fields.Item("acctName").Value) = CStr((rstest.Fields.Item("acctName").Value))) Then Response.Write("SELECTED") : Response.Write("")%> ><%=(rstest.Fields.Item("acctName").Value)%></option>
<%
rstest.MoveNext()
Wend
If (rstest.CursorType > 0) Then
rstest.MoveFirst
Else
rstest.Requery
End If
%>
</select>
<br>
<input type="text" name="txtID">
</form>

My problem is that I keep populating the textbox with the accountName instead of the corresponding acctNumber.

thanks for any help,

Jay
 
Please post the resulting HTML rather than the server side ASP, as not eveybody is familiar with asp but also so we may see what JS sees.

As a guess its because you are populating the <option> values with acctName in your ASP code. So you get a name rather than a number.

Code:
<option value="<%=(rstest.Fields.Item("[red]acctName[/red]").Value)%>"

----------------------------------
Phil AKA Vacunita
----------------------------------
Ignorance is not necessarily Bliss, case in point:
Unknown has caused an Unknown Error on Unknown and must be shutdown to prevent damage to Unknown.

Behind the Web, Tips and Tricks for Web Development.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top