473,748 Members | 2,426 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Could we retrieve the value from a populated pull down menu and reuse that value

46 New Member
Hello Experts.

Is it possible to retrieve the value from a populated pull down menu from a database and then use that value to access the same database to get the related fields.


Example:

Database name: sp
Table: importer
Field names: imp_code, imp_name, imp_address, imp_tel

My Codes:

Expand|Select|Wrap|Line Numbers
  1.  <% 'access adatabase and retrieve field to be displayed on pull down menu%>
Expand|Select|Wrap|Line Numbers
  1. <% dim adocon, adorst, strSQL
  2.  
  3. set adocon = server.createobject("ADODB.connection")
  4. adocon.open" Provider = Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("sp.mdb")
  5.  
  6. set adorst = server.createobject("ADODB.recordset")
  7.  
  8. strSQL="SELECT * FROM importer"
  9. adorst.open strSQL, adocon
  10. %>
[code]

<Form name="hello" id="hello">
<SELECT name="impcode" onChange="Valid ate();">
<%

Do while not adorst.EOF
%>
<option><%=ador st.Fields("imp_ code")%>
<%
adorst.movenext
loop
adocon.close
adorst.close
%>
</option>
</SELECT>
</Form>




Expand|Select|Wrap|Line Numbers
  1.  <% 'access the database again through the selected imp_code and retrieve all related fields to be displayed on text boxes in another form%>
Expand|Select|Wrap|Line Numbers
  1. <% dim adocon1, adorst1, strSQL1
  2.  
  3. set adocon1 = server.createobject("ADODB.connection")
  4. adocon1.open" Provider = Microsoft.Jet.OLEDB.4.0;Data source=" & Server.MapPath ("sp.mdb")
  5.  
  6. set adorst1 = server.createobject("ADODB.recordset")
  7.  
  8. strSQL1="SELECT * FROM importer WHERE imp_code=***please. This i don't know how to code, may be we can get the value from the <javascript function Validate>"
  9.  
  10. adorst.open strSQL, adocon
  11.  
  12. Response.write"<input name="impname" value=[***please. this i don't know]>"
  13. Response.write"<input name="impaddress" value=[***please. this i don't know]>"
  14. Response.write"<input name="imptel" value=[***please. this i don't know]>"
  15.  
  16. adocon.close
  17. adorst.close
  18.  
  19. %>

Expand|Select|Wrap|Line Numbers
  1. <script language="javascript" type="text/javascript">
  2. function Validate()
  3. {
  4. document.hello.impcode.value=document.hello.impcode.options[document.hello.impcode.selectedIndex].value
  5. }
  6. </script>
  7.  

Waiting eagerly for your suggestion ...........

Thanks

Giandeo
Jan 30 '08 #1
21 2895
DrBunchman
979 Recognized Expert Contributor
Hi Giandeo,

Rather than using javascript why don't you use a button to submit your form then use Request("ImpCod e") in strSQL1? e.g.

strSQL1="SELECT * FROM importer WHERE imp_code=Reques t("ImpCode")

Does this help?

Dr B
Jan 30 '08 #2
giandeo
46 New Member
Hi Giandeo,

Rather than using javascript why don't you use a button to submit your form then use Request("ImpCod e") in strSQL1? e.g.

strSQL1="SELECT * FROM importer WHERE imp_code=Reques t("ImpCode")

Does this help?

Dr B
Thank you so much DrBunchman for your kind quick reply and indelible help.

Frankly speaking, I have a page to submit with a number of fields. In that page I have two populated pull down menu with associated text boxes and some non related text fields. I want to populate the text boxes from the relative tables once the user select an option on the pull down menu. As such there is no need for them to key in the data. For the non related fields such as description of goods, country of origin data will have to be input manually. Once the information is complete, we submit the page and update the transaction table.


Example:

Selecting an option from importer drop down menu automatically populates the importer text boxes:- name, address, telephone from the importer table

After that, selecting an option from the declarant menu automatically populates the declarant text boxes - declarant name, declarant address, declarant telephone from the declarant table

After that, key in the description of goods in a text box

After that, key in the origin in a text box

Finally, submit the page/form to update the table transaction with fields:- imp_code, declarant_code, description,ori gin

My problem
Its almost a month or so now. I am new to ASP and Web programming. I can find some bits of information here and some there and I try to understand the logic behind and then share the knowledge to others. But unfortunately, this time I am in a 'no move' situation.

I have been able to populate a pull down menu(e.g imp_code) from the associated table(e.g importer) but I am not able to populate the relative text fields/boxes (e.g imp_name, imp_address, imp_tel). And then if you have two pull down menu matters become worst from bad.

I wish i could get that magic help from you experts that could show me how to do such tricks....
Jan 30 '08 #3
DrBunchman
979 Recognized Expert Contributor
The following code shows how you can use javascript to populate a number of text boxes after selecting a value from a drop down list. Note that this code does not use the second database call - it gets all the data it needs from the first call and stores it in the value field of the drop down list. The javascript then takes that value, splits it into an array and puts it into the text boxes.


Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript" type="text/javascript">
  3. function TestScript(strvalues)
  4. {
  5. //this function takes the long string of values from the database and splits it up
  6. //into the original pieces of data
  7. var arrayvalues = strvalues.split(","); 
  8. document.form1.TextBox1.value = arrayvalues[0];
  9. document.form1.TextBox2.value = arrayvalues[1];
  10. // add as many lines here as you need, one for each textbox value you want to set
  11. }
  12. </script>
  13. <form name="form1">
  14. <select name="Select1" onchange = "TestScript(this.options[this.selectedIndex].value)">
  15. <option value="0" />
  16.  
  17. <!-- CYCLE THROUGH EACH ROW IN THE RECORD SET AND STORE THE REQUIRED VALUES IN THE OPTION -->
  18.  
  19. <%
  20. Do Until adorst.EOF
  21. 'ADD AS MANY VALUES AS YOU NEED FROM THE RECORDSET BUT MAKE SURE YOU
  22. 'PUT A COMMA BETWEEN EACH ONE AS I HAVE BELOW
  23.  
  24. Response.Write("<Option value='" & adorst("DBValue1") & "," & adorst("DBValue2") & "'>
  25. Response.Write(adorst("imp_code"))
  26. Response.Write("</option>")
  27.  
  28. adorst.MoveNext
  29. Loop
  30. %>
  31.  
  32. </select>
  33. <input type="text" name="TextBox1" />
  34. <input type="text" name="TextBox2" />
  35. </form>
  36.  
If you need any help implementing this then give me a shout as I probably haven't explained it very well. I hope this is a solution to your problem.

Dr B
Jan 30 '08 #4
CroCrew
564 Recognized Expert Contributor
Hello giandeo,

This one was fun to figure out! I don’t know if this is your answer but, it might work for you.

First off I don’t know the fields within your database so you will need to change a few things before you test:
  • Change the SQL syntax to match your fields within your table.
  • Change the field names within all the “Do Until” loops.

What I like about doing it this way is there is only one call to your database (DBA’s are big fans of that) and should speed up your page. The other thing is that there is no page reload; all the data is stored in an array.


Hope this helps~

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("sp.mdb") 
  4.     Set rsList = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT FieldOne, FieldTwo, FieldThree FROM TheTable"
  6.     rsList.CursorType = 1
  7.     rsList.LockType = 3
  8.     rsList.Open SQL, Conn
  9. %>
  10. <html>
  11.     <head>
  12.         <title>Example</title>
  13.         <script language="JavaScript">
  14.             var FieldOneArray = new Array(<%=rsList.RecordCount%>);
  15.             var FieldTwoArray = new Array(<%=rsList.RecordCount%>);
  16.             var FieldThreeArray = new Array(<%=rsList.RecordCount%>);
  17.                 <%i = 0%>
  18.                 <%Do Until (rsList.EOF)%>
  19.                     FieldOneArray[<%=i%>]='<%=rsList("FieldOne").value%>';
  20.                     FieldTwoArray[<%=i%>]='<%=rsList("FieldTwo").value%>';
  21.                     FieldThreeArray[<%=i%>]='<%=rsList("FieldThree").value%>';
  22.                     <%i = (i + 1)%>
  23.                     <%rsList.MoveNext%>
  24.                 <%Loop%>
  25.  
  26.             function UpdateValues()
  27.             {
  28.                 var TheSelectedValue = document.xForm.PreFillOne.options[document.xForm.PreFillOne.selectedIndex].value;
  29.                 document.xForm.FieldOne.value = FieldOneArray[TheSelectedValue];
  30.                 document.xForm.FieldTwo.value = FieldTwoArray[TheSelectedValue];
  31.                 document.xForm.FieldThree.value = FieldThreeArray[TheSelectedValue];
  32.             }
  33.         </script>
  34.     </head>
  35.     <body>
  36.         <form method="post" action="#" name="xForm" id="xForm">
  37.             <select name="PreFillOne" onchange="UpdateValues();">
  38.                 <option value="-1">Select One</option>
  39.                 <%i = 0%>
  40.                 <%rsList.MoveFirst%>
  41.                 <%Do Until (rsList.EOF)%>
  42.                     <option value="<%=i%>"><%=rsList("FieldOne").value%></option>
  43.                     <%i = (i + 1)%>
  44.                     <%rsList.MoveNext%>
  45.                 <%Loop%>
  46.             </select>
  47.             <br>Field One: <input type="text" name="FieldOne">
  48.             <br>Field One: <input type="text" name="FieldTwo">
  49.             <br>Field One: <input type="text" name="FieldThree">
  50.         </form>
  51.     </body>
  52. </html>
  53.  
Jan 30 '08 #5
giandeo
46 New Member
Hello giandeo,

This one was fun to figure out! I don’t know if this is your answer but, it might work for you.

First off I don’t know the fields within your database so you will need to change a few things before you test:
  • Change the SQL syntax to match your fields within your table.
  • Change the field names within all the “Do Until” loops.

What I like about doing it this way is there is only one call to your database (DBA’s are big fans of that) and should speed up your page. The other thing is that there is no page reload; all the data is stored in an array.


Hope this helps~

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("sp.mdb") 
  4.     Set rsList = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT FieldOne, FieldTwo, FieldThree FROM TheTable"
  6.     rsList.CursorType = 1
  7.     rsList.LockType = 3
  8.     rsList.Open SQL, Conn
  9. %>
  10. <html>
  11.     <head>
  12.         <title>Example</title>
  13.         <script language="JavaScript">
  14.             var FieldOneArray = new Array(<%=rsList.RecordCount%>);
  15.             var FieldTwoArray = new Array(<%=rsList.RecordCount%>);
  16.             var FieldThreeArray = new Array(<%=rsList.RecordCount%>);
  17.                 <%i = 0%>
  18.                 <%Do Until (rsList.EOF)%>
  19.                     FieldOneArray[<%=i%>]='<%=rsList("FieldOne").value%>';
  20.                     FieldTwoArray[<%=i%>]='<%=rsList("FieldTwo").value%>';
  21.                     FieldThreeArray[<%=i%>]='<%=rsList("FieldThree").value%>';
  22.                     <%i = (i + 1)%>
  23.                     <%rsList.MoveNext%>
  24.                 <%Loop%>
  25.  
  26.             function UpdateValues()
  27.             {
  28.                 var TheSelectedValue = document.xForm.PreFillOne.options[document.xForm.PreFillOne.selectedIndex].value;
  29.                 document.xForm.FieldOne.value = FieldOneArray[TheSelectedValue];
  30.                 document.xForm.FieldTwo.value = FieldTwoArray[TheSelectedValue];
  31.                 document.xForm.FieldThree.value = FieldThreeArray[TheSelectedValue];
  32.             }
  33.         </script>
  34.     </head>
  35.     <body>
  36.         <form method="post" action="#" name="xForm" id="xForm">
  37.             <select name="PreFillOne" onchange="UpdateValues();">
  38.                 <option value="-1">Select One</option>
  39.                 <%i = 0%>
  40.                 <%rsList.MoveFirst%>
  41.                 <%Do Until (rsList.EOF)%>
  42.                     <option value="<%=i%>"><%=rsList("FieldOne").value%></option>
  43.                     <%i = (i + 1)%>
  44.                     <%rsList.MoveNext%>
  45.                 <%Loop%>
  46.             </select>
  47.             <br>Field One: <input type="text" name="FieldOne">
  48.             <br>Field One: <input type="text" name="FieldTwo">
  49.             <br>Field One: <input type="text" name="FieldThree">
  50.         </form>
  51.     </body>
  52. </html>
  53.  
[quote]
I heartfully thank you EXPERTS for you remarkable help. I am going to execute the program and will shortly report to you. Thanks again.....
Jan 31 '08 #6
giandeo
46 New Member
Hello giandeo,

This one was fun to figure out! I don’t know if this is your answer but, it might work for you.

First off I don’t know the fields within your database so you will need to change a few things before you test:
  • Change the SQL syntax to match your fields within your table.
  • Change the field names within all the “Do Until” loops.

What I like about doing it this way is there is only one call to your database (DBA’s are big fans of that) and should speed up your page. The other thing is that there is no page reload; all the data is stored in an array.


Hope this helps~

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Set Conn = Server.CreateObject("ADODB.Connection")
  3.     Conn.Open "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=" & Server.MapPath("sp.mdb") 
  4.     Set rsList = Server.CreateObject("ADODB.Recordset")
  5.     SQL = "SELECT FieldOne, FieldTwo, FieldThree FROM TheTable"
  6.     rsList.CursorType = 1
  7.     rsList.LockType = 3
  8.     rsList.Open SQL, Conn
  9. %>
  10. <html>
  11.     <head>
  12.         <title>Example</title>
  13.         <script language="JavaScript">
  14.             var FieldOneArray = new Array(<%=rsList.RecordCount%>);
  15.             var FieldTwoArray = new Array(<%=rsList.RecordCount%>);
  16.             var FieldThreeArray = new Array(<%=rsList.RecordCount%>);
  17.                 <%i = 0%>
  18.                 <%Do Until (rsList.EOF)%>
  19.                     FieldOneArray[<%=i%>]='<%=rsList("FieldOne").value%>';
  20.                     FieldTwoArray[<%=i%>]='<%=rsList("FieldTwo").value%>';
  21.                     FieldThreeArray[<%=i%>]='<%=rsList("FieldThree").value%>';
  22.                     <%i = (i + 1)%>
  23.                     <%rsList.MoveNext%>
  24.                 <%Loop%>
  25.  
  26.             function UpdateValues()
  27.             {
  28.                 var TheSelectedValue = document.xForm.PreFillOne.options[document.xForm.PreFillOne.selectedIndex].value;
  29.                 document.xForm.FieldOne.value = FieldOneArray[TheSelectedValue];
  30.                 document.xForm.FieldTwo.value = FieldTwoArray[TheSelectedValue];
  31.                 document.xForm.FieldThree.value = FieldThreeArray[TheSelectedValue];
  32.             }
  33.         </script>
  34.     </head>
  35.     <body>
  36.         <form method="post" action="#" name="xForm" id="xForm">
  37.             <select name="PreFillOne" onchange="UpdateValues();">
  38.                 <option value="-1">Select One</option>
  39.                 <%i = 0%>
  40.                 <%rsList.MoveFirst%>
  41.                 <%Do Until (rsList.EOF)%>
  42.                     <option value="<%=i%>"><%=rsList("FieldOne").value%></option>
  43.                     <%i = (i + 1)%>
  44.                     <%rsList.MoveNext%>
  45.                 <%Loop%>
  46.             </select>
  47.             <br>Field One: <input type="text" name="FieldOne">
  48.             <br>Field One: <input type="text" name="FieldTwo">
  49.             <br>Field One: <input type="text" name="FieldThree">
  50.         </form>
  51.     </body>
  52. </html>
  53.  
Sir, the solution works perfectly well so long there is no appostrophe ' in the record. Let me explain.

I have a table importer with the following fields:
Imp_code, imp_name, imp_address

I can retrieve all the values for
Imp_code = 00011, Imp_name=Gerrar d, Imp_address=15, Garcia Road, B Bay

But I cannot retrieve data for
Imp_code = 00012, Imp_name=Raoul, imp_address=Roy al Road Trou D'eau Douce

The pull down menu cannot display the values stored in the array. I get the message/warning "Loaded by with errors". Although the pull down menu is populated with the values of the imp_coded, no record is displayed in the text fields.

Please help me out.......
Feb 11 '08 #7
CroCrew
564 Recognized Expert Contributor
Hello giandeo,

Are you trying to say something? It is not coming in if you are. Please re-post what your trying to say and preview it before posting.

Thanks~
Feb 11 '08 #8
giandeo
46 New Member
Hello giandeo,

Are you trying to say something? It is not coming in if you are. Please re-post what your trying to say and preview it before posting.

Thanks~
Sir, the solution works perfectly well so long there is no appostrophe ' in the record. Let me explain.

The table importer has the following fields:
Imp_code, imp_name, imp_address

I can retrieve all the values for
Imp_code = 00011, Imp_name=Gerrar d, Imp_address=15, Garcia Road, B Bay

But I cannot retrieve data for
Imp_code = 00012, Imp_name=Raoul, imp_address=Roy al Road Trou D'eau Douce

The pull down menu cannot display the values stored in the array. I get the message/warning "Loaded by with errors". Although the pull down menu is populated with the values of the imp_coded, no record is displayed in the text fields.

Please help me out.....
Feb 12 '08 #9
DrBunchman
979 Recognized Expert Contributor
Hi giandeo,

The problem here is that an apostrophe is a special character used by the database to mark the end of a string. If you want to include data with apostrophe's in your records you must replace them all with double apostrophe's. Like so:

Expand|Select|Wrap|Line Numbers
  1. string= Replace(string, "'", "''")
If your string was "Royal Road Trou D'eau Douce" then it would become "Royal Road Trou D''eau Douce" and this could be safely entered in the database.

Does this make sense? Let me know how you get on.

Dr B
Feb 12 '08 #10

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

Similar topics

3
11237
by: julian | last post by:
hi I was wondering if anyone can help me out on this.... I have dynamcally populated a drop down menu with data from an access database using ASP. The values seem fine, however when i pass them to the next page (using form get method) the whitespaces in the values are ignored. For example with <option value=jim jones> then only "jim" gets passed to the next page not "jim jones". I have viewed the source created on the dynamic page and...
1
1503
by: NEUE | last post by:
Hello, I'm trying to have a layer appear on top of a simple pull-down menu, but in IE6 the pull-down menu always appears on top. Even if I put the pull-down in a layer under the other layers, it shows on top. On Firefox and all Mac browsers is fine. Any way around this? Thanks NF
5
5376
by: judiphuongtu | last post by:
I am trying to create an input form with a pull-down menu that allows a user to add an item to the pull-down. I don't want the page to refresh when I refresh the pull-down since there's entries on the form already. Please help! Thanks. jptu
1
3796
by: BuddyWork | last post by:
Hello, When a particular user (has administrator rights) on a Windows 2000 Server SP4 tries to run any MSI's we get the message mentioned in the subject. If we logon with another user that has administrator rights then it works, if we create a new administrator user then it does NOT work, Here is the MSI log, please help as this is causing problems as only 3 users on this box are able to run MSI where are about 15 other users
7
1941
by: Smithers | last post by:
I have a non trivial ASP.NET Web application that implements its navigation system via a user control (menu.ascx) placed on every page. It is important to note that the user control that hosts the menu is injected into every page at runtime when the page is requested (i.e., it's not declared in any ASPX). The user control contains a menu that is dynamically populated and styled at runtime (fwiw: it's ComponentArt's Menu for ASP.NET -...
2
4552
by: Mike Collins | last post by:
I cannot get the correct drop down list value from a drop down I have on my web form. I get the initial value that was loaded in the list. It was asked by someone else what the autopostback was set to...it is set to false. Can someone show me what I am doing wrong and tell me the correct way? Thank you. In the page load event, I am doing the following:
2
3100
by: Keith Burns | last post by:
Hi, I have seen two entries in the archives for this topic: 1. Uses hypertext, not a pulldown menu to feed parameters back to the python CGI 2. The other actually used Java. Is there a way using Python for CGI such that when a user selects an item from one pull down menu (ie FRUIT or VEGETABLE or MEAT) that another pull
1
1692
by: dkimbrell | last post by:
Hi there, I'm very novice to web design. I'm trying to make a pulldown menu, but the formatting keeps getting screwed up when you roll the mouse over it. Please see www.boundarysys.com for what I'm talking about. Before the mouse touches the pulldown, the vertical height of the menubar is perfect. As soon as the mouse rolls over it, it expands to about twice the height.
1
3053
by: azeemqaiser | last post by:
Hi All, I have a form with two drop down controls. I want to change the values of Drop Down Menu 2 if i select some value in Drop Down Menu 1. Like If i select country then all the states of this country should get populated in the second menu. Will appreciate your help.
0
9530
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9363
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9312
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8237
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6793
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6073
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4593
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
4864
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
2775
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.