473,397 Members | 2,116 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

How to use a select list result to query a table to populate a textarea

Hi, I'm a total novice to ASP (yesterday was literally the first time I looked at it) but am currently working on an application that will send an e-mail to selected users, the text that goes in the e-mail will be displayed in a textarea and will be loaded from the database but is editable. The text loaded into the textarea will be selected from a select listbox which is populated by the database (I've actually managed to figure that bit out).

What I need to do is figure out how to read the result of the listbox, then use that to query the database and populate the textarea. I was convinced it would be fairly easy as I expected Visual studio to do everything but apparently that's not the case when using SQL 7.

Any advice would be appreciated, it's getting pretty frustrating knowing that this should probably only take an hour or so yet so far I've spent 2 days searching Google and only got half way.

On a side note is there any way to get the search feature on this forum to only search the ASP section?
Oct 5 '07 #1
6 2168
shweta123
692 Expert 512MB
Hi,

Can you please mention more details about

1) How are filling the listbox and Textarea ,I mean are you using the same tables to fill them.

2) The TextArea is containing emailText I think but what your listbox is containg?




Hi, I'm a total novice to ASP (yesterday was literally the first time I looked at it) but am currently working on an application that will send an e-mail to selected users, the text that goes in the e-mail will be displayed in a textarea and will be loaded from the database but is editable. The text loaded into the textarea will be selected from a select listbox which is populated by the database (I've actually managed to figure that bit out).

What I need to do is figure out how to read the result of the listbox, then use that to query the database and populate the textarea. I was convinced it would be fairly easy as I expected Visual studio to do everything but apparently that's not the case when using SQL 7.

Any advice would be appreciated, it's getting pretty frustrating knowing that this should probably only take an hour or so yet so far I've spent 2 days searching Google and only got half way.

On a side note is there any way to get the search feature on this forum to only search the ASP section?
Oct 5 '07 #2
Hi, yes both the listbox and textarea are hitting the same table, I've made a little progress on it though have included an extra button now too. My code is as follows:

Expand|Select|Wrap|Line Numbers
  1. <%
  2. Dim strEmailType
  3. Dim strContents
  4. strContents=NULL
  5. strEmailType= NULL
  6. %>
  7. <%
  8. set objconn=server.CreateObject("ADODB.connection")
  9. objconn.Open ("DSN=localserver; User ID=User; Password=Pwd")
  10. set rs2=objconn.execute ("SELECT * from Grades_email_tbl")
  11. 'set rs3=objconn.execute ("SELECT emailContents from Grades_email_tbl WHERE EmailType ='"&strEmailType&"'")
  12. %> 
  13. <% 
  14. strEmailType = Request.Form("Select1")%>
  15. <%
  16. If strEmailType = "Failed" then
  17.      strContents="Bah"
  18. Else
  19.     strContents=rs2("emailContents")
  20. End if
  21. %>  
  22. <form method="post">
  23.  
  24. <select name=select1>
  25.  
  26. <%do while not rs2.eof %>
  27. <option><%=rs2(0)%></option>
  28. <%
  29. rs2.movenext
  30. loop
  31. rs2.Close 
  32. set rs2 = nothing
  33. objconn.Close
  34. set objconn=nothing
  35. %>
  36. </select>
  37. <input type=Submit value=Go! />
  38. &nbsp;
  39. &nbsp;
  40. <br />
  41. <textarea style="width: 561px; height: 60px" id="emailtxt">
  42. <%=strContents%>
  43. </textarea>
  44. </form>
  45. <tr><td align="center"  colspan="8">
  46.     <input id="Save" type="submit" value="Save" />
  47.     <input type="submit" value="Send" name="submit1">
  48. </td></tr>
  49. </table>
  50.  
  51. </body></html>
  52.  
At present the listbox populates fine and I've managed to extract the value and place it into the variable strEmailType, what I can't seem to do is get the value emailContents that corresponds to the selected option from the dropdown. I'm trying to get it from the recordset rs2 but at present it only displays the first record from the table, I know I could hardcode it for a quick fix but I'd rather future proof it a bit.

I'm thinking about taking the value of strEmailType and querying the database to return the value of emailContents I want but I'm convinced I can get the value from the rs2 recordset, afterall it should have selected all the information from the table.

The most frustrating thing is knowing it's probably a 2 minute fix
Oct 5 '07 #3
jhardman
3,406 Expert 2GB
On a side note is there any way to get the search feature on this forum to only search the ASP section?
No, sorry. We keep bugging the administration but to no avail. You could post to that effect in the feedback section.

Jared
Oct 5 '07 #4
jhardman
3,406 Expert 2GB
I really like to take this type of thing one step at a time. First off check to make sure your form inputs are being submitted to the next page like this:
Expand|Select|Wrap|Line Numbers
  1. dim x
  2. for each x in request.form
  3.    response.write x & ": " & request.form(x) & "<br>" & vbNewLine
  4. next
Then make the appropriate SQL query:
Expand|Select|Wrap|Line Numbers
  1. dim query
  2. query = "SELECT emailContents FROM Grades_email_tbl WHERE EmailType ='"&strEmailType&"'"
Then print out the query to make sure it looks right:
Expand|Select|Wrap|Line Numbers
  1. response.write "query: " & query & "<br>" & vbNewLine
Then open the dbconnection:
Expand|Select|Wrap|Line Numbers
  1. set rs3 = server.createObject("ADODB.recordset")
  2. rs3.open query, objConn
Then put this in the textarea:
Expand|Select|Wrap|Line Numbers
  1. <textarea id="emailtxt"><%=rs3("emailContents")%></textarea>
Try out these steps and see if this works for you.

Jared
Oct 5 '07 #5
Thanks very much, that's got it working. Sorry about the delay in replying but I couldn't test it at home as I'm still setting up visual studio to work with SQL 2005 on Vista which has started to turn into a nightmare, especially with IIS 7 thrown into the equation.
Oct 8 '07 #6
No, sorry. We keep bugging the administration but to no avail. You could post to that effect in the feedback section.

Jared
Just found this by chance:
http://www.thescripts.com/forum/search.php?
Not quite sure how I got to that link but it allows me to select just the ASP forum for a search
Oct 9 '07 #7

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

Similar topics

23
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
18
by: ian justice | last post by:
Before i post actual code, as i need a speedyish reply. Can i first ask if anyone knows off the top of their head, if there is a likely obvious cause to the following problem. For the moment i've...
5
by: malcolm | last post by:
Example, suppose you have these 2 tables (NOTE: My example is totally different, but I'm simply trying to setup the a simpler version, so excuse the bad design; not the point here) CarsSold {...
9
by: Prowler | last post by:
In our current application we have a page whose sole purpose for existence is to permit the user to select from a list (subsequent to our login page). We would like to have the list drop down...
3
by: Astra | last post by:
Hi All Wondered if you could help me with the below query. I have 1 simple table called STOCKCATS that consists of 2 fields. These fields are called CATID and LEVEL. The contents of this...
3
by: syounger | last post by:
Hi. I have a report in Access 2000 that is based on selection made from a series of interdependent list boxes. The boxes I have right now are Source, Table, Column, Date. The user chooses Source...
16
by: Richard Maher | last post by:
Hi, I have this Applet-hosted Socket connection to my server and in an ONevent/function I am retrieving all these lovely rows from the server and inserting them into the Select-List. (The on...
1
by: impostor | last post by:
I have a query that works fine with single state selections but I need to be able to query based on multiple state selections in a multiple select list and populate the second textarea on the same...
1
by: KrazyKasper | last post by:
Access 2003 – Multi-Column List Box – Select Multiple Items I have a multi-column (3 columns) list box that works well to select one set of records or all sets of records (based on the first field...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
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...
0
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
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...

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.