472,119 Members | 1,162 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,119 software developers and data experts.

Display form details based on populated drop down menu

46
Hello all,

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
  1. <%@ Language=VBScript %>
  2. <%Option explicit
  3. Dim oRs, conn, connect, strSQL, RSyeshti
  4.  
  5. set conn=server.CreateObject ("adodb.connection")
  6. connect = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=" & Server.MapPath("sp.mdb") & ";Persist Security Info=False"
  7. conn.Open connect
  8.  
  9. %>
  10.  
  11. <html>
  12. <head>
  13. <script language="javascript">
  14. <!--
  15.  
  16. function myfunc(hello) {
  17. var impcode;
  18. impcode=document.hello.impcode.value;
  19. document.hello.thename.value=impcode;
  20. }
  21.  
  22.  
  23. //-->
  24. </script>
  25.  
  26.  
  27. </head>
  28.  
  29. <body>
  30.  
  31.     <SELECT name="impcode" onchange="myfunc(this);">
  32.     <%        
  33.     Set oRs=Server.CreateObject("adodb.recordset")
  34.     strSQL = "SELECT * FROM importer ORDER BY imp_code"
  35.     oRs.Open strSQL, conn        
  36.  
  37.  
  38.     Do while not oRs.EOF
  39.         if Request.Form("impcode")= oRs("imp_code") then 'if this is the selected one then display as selected
  40.             Response.Write "<OPTION VALUE = '" & oRS ("imp_code") & "' SELECTED>"
  41.             Response.Write oRs("imp_code") & "</Option>"
  42.  
  43.             oRs.MoveNext 
  44.         else
  45.             Response.Write "<OPTION VALUE = '" & oRs ("imp_code") & "'>"
  46.             Response.Write oRs("imp_code") & "</Option>"
  47.             oRs.MoveNext 
  48.         end if
  49.  
  50.       loop        
  51.  
  52.     %>
  53.  
  54. </SELECT>
  55. <%
  56.  
  57. Set oRs=Server.CreateObject("adodb.recordset")
  58. set RSyeshti= conn.Execute("SELECT * FROM importer") 
  59.  
  60. %>
  61. Name:  <input name="thename" type="text" value="<%response.write RSyeshti("imp_name")%>"><br>
  62. Address:  <input name="theaddress" type="text" value="<%response.write RSyeshti("imp_address")%>"><br>
  63. Tel:  <input name="thetel" type="text" value="<%response.write RSyeshti("imp_tel")%>">
  64.  
  65. </form>
  66.  
  67. </body>
  68. </html>
PLEASE help me ...............

Thanks
Jan 25 '08 #1
2 2982
CroCrew
564 Expert 512MB
Give this a try~

Expand|Select|Wrap|Line Numbers
  1. <%
  2.     Set adoCon = Server.CreateObject("ADODB.Connection")
  3.     adoCon.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("sp.mdb") 
  4.  
  5.     Set objRS= Server.CreateObject("ADODB.Recordset") 
  6.         strSQL = "SELECT * FROM importer ORDER BY imp_code"
  7.     objRS.Open strSQL, adoCon
  8. %>
  9. <html>
  10.     <head>
  11.         <title>Example</title>
  12.         <script language="JavaScript">
  13.             function Validate()
  14.             {
  15.                 for(var i = 0; i < NumOfRecords+1; i++) 
  16.                 {
  17.                     x=document.getElementById('Row'+i);
  18.                     x.style.display = 'none';
  19.                 }
  20.                 if (document.xform.impcode.value>=0)
  21.                 {
  22.                     x=document.getElementById('Row'+document.xform.impcode.value);
  23.                     x.style.display = '';
  24.                 }
  25.             }
  26.         </script>
  27.     </head>
  28.     <body>
  29.         <form method="post" action="YourNextPage.asp" name="xform" id="xform"> 
  30.             <select name="impcode" onchange="Validate();">
  31.                 <option value="-1">Select One</option>
  32.                 <%i = 0%>
  33.                 <%Do Until (objRS.EOF)%>
  34.                     <option value="<%=i%>"><%=objRS("imp_code").value%></option>
  35.                     <%i = (i + 1)%>
  36.                     <%objRS.MoveNext%>
  37.                 <%Loop%>
  38.             </select>
  39.             <script language="JavaScript">var NumOfRecords = <%=i%>;</script>
  40.             <table>
  41.                 <%i = 0%>
  42.                 <%objRS.MoveFirst%>
  43.                 <%Do Until (objRS.EOF)%>
  44.                     <tr id="Row<%=i%>" style="display: none;">
  45.                         <td>
  46.                             Name: <input name="thename" type="text" value="<%=objRS("imp_name").value%>"><br>
  47.                             Address: <input name="theaddress" type="text" value="<%=objRS("imp_address").value%>"><br>
  48.                             Tel: <input name="thetel" type="text" value="<%=objRS("imp_tel").value%>">
  49.                         </td>
  50.                     </tr>
  51.                     <%i = (i + 1)%>
  52.                     <%objRS.MoveNext%>
  53.                 <%Loop%>
  54.             </table>
  55.         </form>
  56.     </body>
  57. </html>
  58.  
Jan 25 '08 #2
giandeo
46
Extremely Sorry for the late reply. I don't have internet accesss at home.

Heartfully thanks a lot for your help.
I have given it a try. I have loaded the source code and noted the following:-

I could see the populated drop down menu only.

No text box:-
Expand|Select|Wrap|Line Numbers
  1.   Name: <input name="thename" type="text" value="<%=objRS("imp_name").value%>"><br>
  2.                             Address: <input name="theaddress" type="text" value="<%=objRS("imp_address").value%>"><br>
  3.                             Tel: <input name="thetel" type="text" value="<%=objRS("imp_tel").value%>">
  4.  
When I removed "display: none" from the code <tr id="Row<%=i%>" style="display: none;"> I could see the static list of all records from table importer displayed sequentially. Selecting an option from the drop down list does not change the text box field values.
Jan 28 '08 #3

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

6 posts views Thread by paul | last post: by
1 post views Thread by Jimmy Stewart | last post: by
reply views Thread by Child X | last post: by
2 posts views Thread by Medran | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.