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.

<%
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.

<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

do you have master table for App_Type?
if yes you may check using POS (which identifies substring).

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"

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.

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.

<%@ 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>

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.

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

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.

hei..
u have got the problem while inserting the record or displaying the record?? hmm..

This question has already been answered. Start a new discussion instead.