Combo and textbox exampleHere is the code for this Example <!-- Author: Adrian Forbes --> <% strconn = "Driver={SQL Server};Description=sqldemo;SERVER=127.0.0.1;UID=LoginID;PWD=Password;DATABASE=Database_Name set conn = server.createobject("adodb.connection") conn.open strconn set objRS = createobject("ADODB.Recordset") objRS.Open "select ID, strParent, intValue from Parents", strconn if Request("cboPrimary") = "" then lPrimary = objRS("ID") else lPrimary = clng(Request("cboPrimary")) end if %> <form name=frmTest action="ComboTextboxLinked.asp" method=POST> <p> <select name=cboPrimary size=1 onChange="PopulateTextbox();"> <%while not objRS.EOF lID = clng(objRS("ID"))%> <option value="<%=lID%>"<%if lPrimary = lID then Response.Write " SELECTED"%>><%=objRS("strParent")%> <% objRS.MoveNext wend %> </select> <input type=TEXT name=txtValue> </p> <p> <input type=SUBMIT value="Select" id=SUBMIT1 name=SUBMIT1> </p> </form> <% objRS.MoveFirst while not objRS.EOF%> <input type=HIDDEN ID="intValue<%=objRS("ID")%>" value="<%=objRS("intValue")%>"> <%objrs.MoveNext wend objRS.Close set objRS.ActiveConnection = nothing set objRS = nothing %> <script language=VBScript> sub window_onLoad PopulateTextbox end sub
sub PopulateTextbox lID = document.frmTest.cboPrimary.value document.frmTest.txtValue.value = document.all("intValue" & lID).value end sub </script> |