469,314 Members | 2,210 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,314 developers. It's quick & easy.

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 1939
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

Post your reply

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

Similar topics

23 posts views Thread by ian justice | last post: by
18 posts views Thread by ian justice | last post: by
9 posts views Thread by Prowler | last post: by
1 post views Thread by impostor | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Geralt96 | last post: by
reply views Thread by harlem98 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.