It's almost a couple of weeks since i am struggling to get this code work. Unfortunately, i am stuck. There seems to be no hope... Please Help.......
I am working with an asp page that dynamically pulls info from my database to populate a drop down menu. Upon an onChange event, I wish to display the fields related to that pull down menu WITHOUT SUBMITTING THE PAGE.
The Senario:
Database name: sp.mdb
Table name: importer
Field names: imp_code, imp_name, imp_address, imp_tel
drop down menu resides the imp_code
Once an imp_code is selected from the drop down list, I wish to display the associated fields viz.., imp_name, imp_address, imp_tel in the text fields
The Code:
I am completely new in this field. Nevertheless, i have given it a try. My code is as follows:
Expand|Select|Wrap|Line Numbers
- <%@ Language=VBScript %>
- <%Option explicit
- Dim oRs, conn, connect, strSQL, RSyeshti
- set conn=server.CreateObject ("adodb.connection")
- connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("sp.mdb") & ";Persist Security Info=False"
- conn.Open connect
- %>
- <html>
- <head>
- <script language="javascript">
- <!--
- function myfunc(hello) {
- var impcode;
- impcode=document.hello.impcode.value;
- document.hello.thename.value=impcode;
- }
- //-->
- </script>
- </head>
- <body>
- <SELECT name="impcode" onchange="myfunc(this);">
- <%
- Set oRs=Server.CreateObject("adodb.recordset")
- strSQL = "SELECT * FROM importer ORDER BY imp_code"
- oRs.Open strSQL, conn
- Do while not oRs.EOF
- if Request.Form("impcode")= oRs("imp_code") then 'if this is the selected one then display as selected
- Response.Write "<OPTION VALUE = '" & oRS ("imp_code") & "' SELECTED>"
- Response.Write oRs("imp_code") & "</Option>"
- oRs.MoveNext
- else
- Response.Write "<OPTION VALUE = '" & oRs ("imp_code") & "'>"
- Response.Write oRs("imp_code") & "</Option>"
- oRs.MoveNext
- end if
- loop
- %>
- </SELECT>
- <%
- Set oRs=Server.CreateObject("adodb.recordset")
- set RSyeshti= conn.Execute("SELECT * FROM importer")
- %>
- Name: <input name="thename" type="text" value="<%response.write RSyeshti("imp_name")%>"><br>
- Address: <input name="theaddress" type="text" value="<%response.write RSyeshti("imp_address")%>"><br>
- Tel: <input name="thetel" type="text" value="<%response.write RSyeshti("imp_tel")%>">
- </form>
- </body>
- </html>
Thanks