Click to See Complete Forum and Search --> : Dependent Listbox - Textbox


Rashar
12-04-2004, 08:29 PM
Hi,

Not sure if this is an asp or javascript question, but, I have a dropdown list box that populates a list of customers using asp code which calls the data from a sql server database. The table, tblUsers, contains Customer name and Customer number.

What I would like to do is to be able to select a customer name from the dropdown listbox, and have their customer number populate into a textbox which will be a hidden field.

I guess I could modify my table so that one column holds the cust name and number, but I would like to see if this is possible in asp first.

Thanks,

Rashar

russell
12-04-2004, 11:19 PM
It's kinda both JS and ASP question:

<script><!--
function setCustId() {
newCustId = document.myForm.customer.options[document.myForm.customer.options.selectedIndex].value;
document.myForm.custId.value = newCustId;
}
// -->
</script>

<%
Dim sql
dim rs
Dim cmd
Dim ar
Dim i

sql = "SELECT custId, custName FROM customers"

Set cmd = Server.CreateObject("ADODB.Command")
Set rs = Server.CreateObject("ADODB.Recordset")

With cmd
.ActiveConnection = myConnectionString
.commadType = 1 'adCmdText
.commandText = sql

rs.open .Execute
End With

ar = rs.GetRows
rs.Close
set rs = nothing
set cmd = nothing

With Response
.Write "<form name=myForm>" & vbCrLf
.Write "<input type=hidden name=""custId"">" & vbCrLf
.Write "<select name=""customer"" onchange=""setCustId()"">" & vbCrLf

For i = 0 to ubound(ar, 2)
.Write "<option value=" & ar(0, i) & ">" & ar(1, i) & "</option>" & vbCrLf
Next

.Write "</select>" & vbCrLf
.Write "</form>" & vbCrLf
End With
%>

Rashar
12-05-2004, 10:17 AM
russell, Thanks for your reply. That worked nicely. Do you have any recommendations for ASP / Java Script text book materials?

Best Regards,

Rashar

russell
12-05-2004, 01:02 PM
The best is probably Wrox Press ASP 3.0 Programmers Reference.

MSDN Library ASP (http://msdn.microsoft.com/library/default.asp?url=/library/en-us/iissdk/iis/asp.asp) is pretty good too

buntine
12-06-2004, 01:37 AM
Note, The programmers reference is probably not the best option for a beginner (an excellent resource, though). Try the Beginning ASP 3.0 from Wrox if your just beginning.

Regards.