| | |
Uing the Split Variable in ASP
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
Thread Solved |
•
•
Join Date: May 2008
Posts: 25
Reputation:
Solved Threads: 0
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.
For example the user selects two options i.e Freelance, Self-Employed that I can retrieve using the For Next Loop.
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
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.
ASP Syntax (Toggle Plain Text)
<% strSQL = SELECT APP_JOB FROM TBLAPPLICANTS Set RSAPPLICANT = Server.CreateObject("ADODB.Recordset") RSAPPLICANT.open strSQL,Conn Dim strjob strjob = RSAPPLICANT("APP_JOB") choice=Split(strjob, ",") %>
For example the user selects two options i.e Freelance, Self-Employed that I can retrieve using the For Next Loop.
ASP Syntax (Toggle Plain Text)
<form id="form1" name="form1" method="post" action=""> <select name="mnustylisttype" size="4" multiple="MULTIPLE" class="DropdownFields"> <% For i = LBound(choice) TO UBound(choice) %> <option value="<%=choice(i)%>"><%=choice(i)%></option> <% Next %> </select> </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
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 1
do you have master table for App_Type?
if yes you may check using POS (which identifies substring).
if yes you may check using POS (which identifies substring).
•
•
Join Date: May 2008
Posts: 25
Reputation:
Solved Threads: 0
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.
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.
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.
ASP Syntax (Toggle Plain Text)
<%@ Language="VBScript" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <% dim CN dim RS dim strApp dim strjob dim strOptions dim strSQL dim strType '<open connection CN here> '. '. '<create recordset RS here> '. '. 'Get saved record strSQL="select APP_JOB from TBLAPPLICANTS" rs.open strSQL, cn 'If no records returned, don't select any in the dropdown if not (rs.bof and rs.eof) then strjob=rs("APP_JOB") rs.close strApp = 1 else strApp = 0 end if strOptions="" 'Get all of the applicant types strSQL="select TYPE from APP_TYPE" rs.open strSQL,cn if not (rs.bof and rs.eof) then 'Test each applicant type against the saved record while not rs.eof strOptions = strOptions & "<option value=""" & rs("TYPE") & """" if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then strOptions = strOptions & " selected="""selected""" end if strOptions = strOptions & ">" & rs("TYPE") & "</option>" rs.MoveNext wend end if rs.close %> <html xmlns="http://www.w3.org/1999/xhtml" > <head> <title>Untitled Page</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <select name="mnustylisttype" size="4" multiple="MULTIPLE" class="DropdownFields"> <%=strOptions%> </select> </form> </body> </html>
•
•
Join Date: Apr 2008
Posts: 45
Reputation:
Solved Threads: 1
ASP Syntax (Toggle Plain Text)
instead of if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then strOptions = strOptions & " selected="""selected""" end if write this if instr(strjob,rs("TYPE") )>0 AND strApp = 1 then strOptions = strOptions & " selected " end if
•
•
Join Date: May 2008
Posts: 25
Reputation:
Solved Threads: 0
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.
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.
![]() |
Other Threads in the ASP Forum
- Previous Thread: please help with allowing multiple part numbers to display
- Next Thread: SQL Like Statement in ASP
| Thread Tools | Search this Thread |
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection connection database databaseconnection dreamweaver excel fso iis msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile record searchbox selectoption single specfic sqlserver sqlserverconnection windows7





