By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,740 Members | 844 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,740 IT Pros & Developers. It's quick & easy.

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

P: 46
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="Validate();">
<%

Do while not adorst.EOF
%>
<option><%=adorst.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
Share this Question
Share on Google+
21 Replies


DrBunchman
Expert 100+
P: 979
Hi Giandeo,

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

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

Does this help?

Dr B
Jan 30 '08 #2

P: 46
Hi Giandeo,

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

strSQL1="SELECT * FROM importer WHERE imp_code=Request("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,origin

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
Expert 100+
P: 979
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
Expert 100+
P: 563
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

P: 46
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

P: 46
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=Gerrard, Imp_address=15, Garcia Road, B Bay

But I cannot retrieve data for
Imp_code = 00012, Imp_name=Raoul, imp_address=Royal 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
Expert 100+
P: 563
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

P: 46
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=Gerrard, Imp_address=15, Garcia Road, B Bay

But I cannot retrieve data for
Imp_code = 00012, Imp_name=Raoul, imp_address=Royal 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
Expert 100+
P: 979
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

P: 46
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
Thank you very much Dr B for your suggestion

Frankly speaking, Sir, a double apostrophe will lead to confusion in the mind of the users. It changes the meaning and spelling of the word. Never mind the war is on. I'll try my level best and if you experts have a suggestion, so please come to my rescue.
Feb 12 '08 #11

DrBunchman
Expert 100+
P: 979
Don't worry Giandeo, the double apostrophe won't appear in your database and your users won't even realise it has happened.

They will enter the data as

"Royal Road Trou D'eau Douce"

Using strAddress = Replace(strAddress, "'", "''") in your code will change it to:

"Royal Road Trou D''eau Douce"

But the database will interpret the double apostrophe as single one and display it as

"Royal Road Trou D'eau Douce"

As long as you run that little code snippet on every string you are entering into the database you won't get a problem with the apostrophe's.

Does this make sense? I suggest you give it a try and see how you get on.

Let me know if you need any more help,

Dr B
Feb 12 '08 #12

P: 46
Don't worry Giandeo, the double apostrophe won't appear in your database and your users won't even realise it has happened.

They will enter the data as

"Royal Road Trou D'eau Douce"

Using strAddress = Replace(strAddress, "'", "''") in your code will change it to:

"Royal Road Trou D''eau Douce"

But the database will interpret the double apostrophe as single one and display it as

"Royal Road Trou D'eau Douce"

As long as you run that little code snippet on every string you are entering into the database you won't get a problem with the apostrophe's.

Does this make sense? I suggest you give it a try and see how you get on.

Let me know if you need any more help,

Dr B
Sir, I have just tried the code. I could see the double apostrophe in the address field of the database. But, unfortunately, I am not able to display the complete address.

Here is my code:

Code which updates the database

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3.  
  4. dim conn, sql, rs
  5.  
  6. 'create ADO connection and recordset object
  7. set conn=Server.CreateObject("ADODB.Connection")
  8. set rs = Server.CreateObject("ADODB.Recordset")
  9.  
  10. 'we open connection to the database
  11. conn.Open "Provider=Microsoft.Jet.OLEDB.4.0;Data Source="& Server.MapPath("sp.mdb")
  12.  
  13.  
  14. sql="SELECT imp_code,imp_sname, imp_oname, imp_address,imp_tel FROM importer;"
  15. 'Set the lock and cursor type
  16. rs.CursorType=1
  17. rs.LockType=3
  18.  
  19. 'open the recordset with sql query
  20. rs.open sql, conn
  21. 'prepare the database to add a new record and add
  22. dim strAddress
  23. strAddress = Request.Form("theaddress")
  24. strAddress = Replace(strAddress, "'", "''") 
  25.  
  26.  
  27. rs.AddNew
  28. rs.Fields("imp_code")=Request.Form("thecode")
  29. rs.Fields("imp_sname")=Request.Form("thesname")
  30. rs.Fields("imp_oname")=Request.Form("theoname")
  31. rs.Fields("imp_address")=strAddress
  32. rs.Fields("imp_tel")=Request.Form("thetel")
  33.  
  34. 'save the update
  35. rs.update
  36. rs.close
  37.  
  38.  
  39.  
  40. set rs=Nothing
  41. set conn=Nothing
  42. %>
  43.  
  44.  
The database is successfully updated !

Here is the code to retrieve the data from the database as you recommended earlier

Expand|Select|Wrap|Line Numbers
  1.  
  2. <%
  3. Set Conn = Server.CreateObject("ADODB.Connection")
  4. Conn.open "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" &server.mapPath("sp.mdb")
  5.  
  6.  
  7. Set adorst = Server.CreateObject("ADODB.Recordset")  
  8. SQL = "SELECT * FROM importer ORDER BY imp_code"
  9.  
  10. adorst.CursorType = 1
  11. adorst.LockType = 3
  12.  
  13. adorst.Open SQL, Conn
  14. %>
  15.  
  16.  
  17. <script language="javascript" type="text/javascript">
  18. function TestScript(strvalues)
  19. {
  20. //this function takes the long string of values from the database and splits it up
  21. //into the original pieces of data
  22. var arrayvalues = strvalues.split(","); 
  23. document.form1.TextBox1.value = arrayvalues[0];
  24. document.form1.TextBox2.value = arrayvalues[1];
  25. document.form1.TextBox3.value = arrayvalues[2];
  26.  
  27. // add as many lines here as you need, one for each textbox value you want to set
  28. }
  29. </script>
  30. <form name="form1">
  31. <select name="Select1" onchange = "TestScript(this.options[this.selectedIndex].value)">
  32. <option value="0" />
  33.  
  34. <!-- CYCLE THROUGH EACH ROW IN THE RECORD SET AND STORE THE REQUIRED VALUES IN THE OPTION -->
  35.  
  36. <%
  37. Do Until adorst.EOF
  38. 'ADD AS MANY VALUES AS YOU NEED FROM THE RECORDSET BUT MAKE SURE YOU
  39. 'PUT A COMMA BETWEEN EACH ONE AS I HAVE BELOW
  40.  
  41. Response.Write("<Option value='" & adorst("imp_sname") & "," & adorst("imp_oname") & "," & adorst("imp_address") & "'>")
  42. Response.Write(adorst("imp_code"))
  43. Response.Write("</option>")
  44.  
  45. adorst.MoveNext
  46. Loop
  47. %>
  48.  
  49. </select>
  50. <input type="text" name="TextBox1" />
  51. <input type="text" name="TextBox2" />
  52. <input type="text" name="TextBox3" />
  53.  
  54. </form>
  55.  
Please advise .......
Feb 13 '08 #13

DrBunchman
Expert 100+
P: 979
Can you give me an example of how the data is being displayed and how you would expect it to be displayed?

Thanks,

Dr B
Feb 13 '08 #14

CroCrew
Expert 100+
P: 563
Hello giandeo,

Your problem is not with your database. The way you are storing data takes care of double quotes inserts. Where your problem is located is within the JavaScript.

Take a look at this new code snip. Look at lines 19 through 21 and there is where you need to make your changes to handle single quotes.

Sorry for not getting back with you faster. I do hope this helps you out~

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%>]='<%=Replace(rsList("FieldOne"), "'", "\'")%>';
  20.                     FieldTwoArray[<%=i%>]='<%=Replace(rsList("FieldTwo"), "'", "\'")%>';
  21.                     FieldThreeArray[<%=i%>]='<%=Replace(rsList("FieldThree"), "'", "\'")%>';
  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.  
Feb 13 '08 #15

P: 46
Hello giandeo,

Your problem is not with your database. The way you are storing data takes care of double quotes inserts. Where your problem is located is within the JavaScript.

Take a look at this new code snip. Look at lines 19 through 21 and there is where you need to make your changes to handle single quotes.

Sorry for not getting back with you faster. I do hope this helps you out~

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%>]='<%=Replace(rsList("FieldOne"), "'", "\'")%>';
  20.                     FieldTwoArray[<%=i%>]='<%=Replace(rsList("FieldTwo"), "'", "\'")%>';
  21.                     FieldThreeArray[<%=i%>]='<%=Replace(rsList("FieldThree"), "'", "\'")%>';
  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]
Hello CroCrew

Your solution is astonishingly fantastic.
Thank you so so much Sir. With your blessing and other Experts I have won a battle with myself, but the war continues.

Again. Thank you very much and please accept my greeting for the VALENTINE'S DAY.
Feb 14 '08 #16

P: 46
Hello giandeo,

Your problem is not with your database. The way you are storing data takes care of double quotes inserts. Where your problem is located is within the JavaScript.

Take a look at this new code snip. Look at lines 19 through 21 and there is where you need to make your changes to handle single quotes.

Sorry for not getting back with you faster. I do hope this helps you out~

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%>]='<%=Replace(rsList("FieldOne"), "'", "\'")%>';
  20.                     FieldTwoArray[<%=i%>]='<%=Replace(rsList("FieldTwo"), "'", "\'")%>';
  21.                     FieldThreeArray[<%=i%>]='<%=Replace(rsList("FieldThree"), "'", "\'")%>';
  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.  
Hello CroCrew,

Your solution is astonishingly fantastic.

Thank you so so much Sir.
With your blessing and other Experts I have won a battle with myself, but the war continues.

Again. Thank you very much and please accept my greeting for the Valentine's Day
Feb 14 '08 #17

P: 46
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~
Hello CroCrew,

Your solution is astonishingly fantastic. I tried to inform you twice, but unfortunately, there was an error and the message could not be read

Thank you so so much Sir.
With your blessing and other Experts I have won a battle with myself, but the war continues.

Again. Thank you very much and please accept my greeting for the Valentine Day
Feb 14 '08 #18

CroCrew
Expert 100+
P: 563
You are most welcome. Just a bit of advice.. always preview your posts before submitting them that way you won’t get blank posts. But, if by accident you do post a blank post you can always “edit” the post to fix any errors.

Happy coding~
Feb 14 '08 #19

P: 46
You are most welcome. Just a bit of advice.. always preview your posts before submitting them that way you won’t get blank posts. But, if by accident you do post a blank post you can always “edit” the post to fix any errors.

Happy coding~

Sir, sorry to bother you again.

I wish to display the above text fields not through a populated pull down menu but through an input text field.

Meaning that when the user key-in a value in the input text field and presses on the submit button, the FieldOne, FieldTwo and FieldThree are populated and the value input by the user still visible.

Please Sir, Help me out of this trouble
Feb 19 '08 #20

CroCrew
Expert 100+
P: 563
Hello giandeo,

I modified my example code above to meet your new requirements.

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%>]='<%=Replace(rsList("FieldOne"), "'", "\'")%>';
  20.                     FieldTwoArray[<%=i%>]='<%=Replace(rsList("FieldTwo"), "'", "\'")%>';
  21.                     FieldThreeArray[<%=i%>]='<%=Replace(rsList("FieldThree"), "'", "\'")%>';
  22.                     <%i = (i + 1)%>
  23.                     <%rsList.MoveNext%>
  24.                 <%Loop%>
  25.  
  26.             function UpdateValues()
  27.             {
  28.                 var NotFound = true;
  29.                 for (x in FieldOneArray)
  30.                 {
  31.                     if (FieldOneArray[x] == document.xForm.FieldOne.value)
  32.                     {
  33.                         document.yForm.FieldOne.value = FieldOneArray[x];
  34.                         document.yForm.FieldTwo.value = FieldTwoArray[x];
  35.                         document.yForm.FieldThree.value = FieldThreeArray[x];
  36.                         NotFound = false;
  37.                     }
  38.                 }
  39.  
  40.                 if (NotFound){alert("Not found!");}
  41.             }
  42.         </script>
  43.     </head>
  44.     <body>
  45.         <form method="post" action="#" name="xForm" id="xForm">
  46.             Search Field One: <input type="text" name="FieldOne">&nbsp;
  47.             <input type="button" value="Find" onclick="UpdateValues();">
  48.         </form>
  49.         <form method="post" action="#" name="yForm" id="yForm">
  50.             <br>Field One: <input type="text" name="FieldOne">
  51.             <br>Field One: <input type="text" name="FieldTwo">
  52.             <br>Field One: <input type="text" name="FieldThree">
  53.         </form>
  54.     </body>
  55. </html>
  56.  
Feb 19 '08 #21

P: 46
Sir, sorry to bother you again.

I wish to display the above text fields not through a populated pull down menu but through an input text field.

Meaning that when the user key-in a value in the input text field and presses on the submit button, the FieldOne, FieldTwo and FieldThree are populated and the value input by the user still visible.

Please Sir, Help me out of this trouble
Sir, your solution is amazing. It works perfectly well. thank you so much.

Just a last but not the least bit of advice please.

When the input field is blank and on pressing enter, the message Not Found is displayed.

I wish to display this message when the input field is blank. But when the field length is less or greater than the maximum length(e.g 8), I also wish to display a message like that Invalid Input.

Could you advise me please..
Feb 21 '08 #22

Post your reply

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