Uing the Split Variable in ASP

Thread Solved

Join Date: May 2008
Posts: 25
Reputation: whisper_101 is an unknown quantity at this point 
Solved Threads: 0
whisper_101 whisper_101 is offline Offline
Light Poster

Using the Split Variable in ASP

 
0
  #1
May 30th, 2008
Hi Everyone

On an .ASP Webpage I allow users to select more than one option from a list box. To retrieve this information I use the Split Function i.e.

  1. <%
  2. strSQL = SELECT APP_JOB FROM TBLAPPLICANTS
  3.  
  4. Set RSAPPLICANT = Server.CreateObject("ADODB.Recordset")
  5.  
  6. RSAPPLICANT.open strSQL,Conn
  7.  
  8. Dim strjob
  9.  
  10. strjob = RSAPPLICANT("APP_JOB")
  11.  
  12. choice=Split(strjob, ",")
  13. %>

For example the user selects two options i.e Freelance, Self-Employed that I can retrieve using the For Next Loop.

  1. <form id="form1" name="form1" method="post" action="">
  2.  
  3. <select name="mnustylisttype" size="4" multiple="MULTIPLE" class="DropdownFields">
  4.  
  5. <%
  6. For i = LBound(choice) TO UBound(choice)
  7. %>
  8.  
  9. <option value="<%=choice(i)%>"><%=choice(i)%></option>
  10.  
  11. <%
  12. Next
  13. %>
  14.  
  15. </select>
  16. </form>

The options actually come from a list drlistAPP_TYPE a Table that contains the following:

1 Freelance
2 Self-Employed
3 Contract

My question is how do I retreive the options selected by the user i.e. Freelance, Self-Employed and the remaining option available in the drlistAPP_TYPE Table i.e. Contract?

Any help would be good - Thanks Guys
Last edited by peter_budo; May 31st, 2008 at 7:43 am. Reason: Keep It Organized - please use [code] tags
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: pmpn is an unknown quantity at this point 
Solved Threads: 1
pmpn pmpn is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #2
Jun 1st, 2008
do you have master table for App_Type?
if yes you may check using POS (which identifies substring).
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 25
Reputation: whisper_101 is an unknown quantity at this point 
Solved Threads: 0
whisper_101 whisper_101 is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #3
Jun 1st, 2008
Could you give me an example of how this would work?
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: OldDude is an unknown quantity at this point 
Solved Threads: 1
OldDude's Avatar
OldDude OldDude is offline Offline
Newbie Poster

Re: Uing the Split Variable in ASP

 
0
  #4
Jun 2nd, 2008
I'm not sure what happens next to this page, but if the page is posted, all selected options in a "multiple" select are in a comma-delimited list. in your example, if "Freelance" and "Self-Employed" are selected, Request.Form("mnustylisttype") would return "Freelance,Self-Employed"
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 25
Reputation: whisper_101 is an unknown quantity at this point 
Solved Threads: 0
whisper_101 whisper_101 is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #5
Jun 2nd, 2008
ok. This is why I am using the Split Function. But I want to retrieve the values in this variable and loop through the recordset of the table containing Self Employed Freelance and Contract in order to retrieve the values in this recordset that are not the same as those using the Split Function.

So if the user has previously selected and saved Self-Employed and Freelance then upon editing these details the list box would be populated with Self-Employed and Freelance as selected items and Contract as a remaining item available.
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: OldDude is an unknown quantity at this point 
Solved Threads: 1
OldDude's Avatar
OldDude OldDude is offline Offline
Newbie Poster

Re: Uing the Split Variable in ASP

 
0
  #6
Jun 2nd, 2008
In that case, I would forget the split. Keep in mind I can't test this because I don't have a table. In this example I assume the column name of "TYPE" for the data in table APP_TYPE. Hopefully it works closely enough to demonstrate the idea.

  1. <%@ Language="VBScript" %>
  2.  
  3. <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
  4.  
  5. <%
  6. dim CN
  7. dim RS
  8. dim strApp
  9. dim strjob
  10. dim strOptions
  11. dim strSQL
  12. dim strType
  13.  
  14. '<open connection CN here>
  15. '.
  16. '.
  17. '<create recordset RS here>
  18. '.
  19. '.
  20.  
  21. 'Get saved record
  22. strSQL="select APP_JOB from TBLAPPLICANTS"
  23. rs.open strSQL, cn
  24.  
  25. 'If no records returned, don't select any in the dropdown
  26. if not (rs.bof and rs.eof) then
  27. strjob=rs("APP_JOB")
  28. rs.close
  29. strApp = 1
  30. else
  31. strApp = 0
  32. end if
  33.  
  34. strOptions=""
  35.  
  36. 'Get all of the applicant types
  37. strSQL="select TYPE from APP_TYPE"
  38. rs.open strSQL,cn
  39. if not (rs.bof and rs.eof) then
  40. 'Test each applicant type against the saved record
  41. while not rs.eof
  42. strOptions = strOptions & "<option value=""" & rs("TYPE") & """"
  43. if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then
  44. strOptions = strOptions & " selected="""selected"""
  45. end if
  46. strOptions = strOptions & ">" & rs("TYPE") & "</option>"
  47. rs.MoveNext
  48. wend
  49. end if
  50. rs.close
  51. %>
  52.  
  53. <html xmlns="http://www.w3.org/1999/xhtml" >
  54. <head>
  55. <title>Untitled Page</title>
  56. </head>
  57. <body>
  58. <form id="form1" name="form1" method="post" action="">
  59. <select name="mnustylisttype" size="4" multiple="MULTIPLE" class="DropdownFields">
  60. <%=strOptions%>
  61. </select>
  62. </form>
  63. </body>
  64. </html>
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 25
Reputation: whisper_101 is an unknown quantity at this point 
Solved Threads: 0
whisper_101 whisper_101 is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #7
Jun 3rd, 2008
I get an "Expected End of Statement Error at this line:

strOptions = strOptions & " selected="""selected"""

I have tried a few things but none of which have worked.
Reply With Quote Quick reply to this message  
Join Date: Apr 2008
Posts: 45
Reputation: pmpn is an unknown quantity at this point 
Solved Threads: 1
pmpn pmpn is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #8
Jun 3rd, 2008
  1.  
  2. instead of
  3. if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then
  4. strOptions = strOptions & " selected="""selected"""
  5. end if
  6.  
  7. write this
  8. if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then
  9. strOptions = strOptions & " selected "
  10. end if
  11.  
Reply With Quote Quick reply to this message  
Join Date: Mar 2008
Posts: 7
Reputation: OldDude is an unknown quantity at this point 
Solved Threads: 1
OldDude's Avatar
OldDude OldDude is offline Offline
Newbie Poster

Re: Uing the Split Variable in ASP

 
0
  #9
Jun 3rd, 2008
Should be strOptions = strOptions & " selected=""selected"""
Reply With Quote Quick reply to this message  
Join Date: May 2008
Posts: 25
Reputation: whisper_101 is an unknown quantity at this point 
Solved Threads: 0
whisper_101 whisper_101 is offline Offline
Light Poster

Re: Uing the Split Variable in ASP

 
0
  #10
Jun 4th, 2008
I thought I would give it a good testing and it was working fine but after alternating from different options when updating a record I got an error.

Usually when a column is not big enough for the data you want to add you get the following error:

Microsoft OLE DB Provider for ODBC Drivers (0x80040E57)
[Microsoft][SQL Native Client][SQL Server]String or binary data would be truncated.

But I have increased the Field Size several times and still no joy.

Any Ideas? I mean the Field Size is varchar(500) and even all the options i.e Self-Employed, Freelance and Contract should fit in this field.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC