|
|
|||||||||
|
|||||||||
|
|||||||||
| |
||
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Multiple Selections from a list box
Hey,
I have the following problem... I am dynamically creating a list box from values in a database, using the following code. I then want the user to be able to make multiple selections from the list box. -------------------------------------------------------------------------------- <SELECT name=courses LANGUAGE=javascript multiple size="5" > <% Set oRs=Server.CreateObject("adodb.recordset") strSQL = "SELECT DISTINCT CourseName FROM tblCourses ORDER BY CourseName" oRs.Open strSQL, conn Do while not oRs.EOF if Request.Form("courses") = oRs("CourseName") then Response.Write "<OPTION VALUE = '" & oRS ("CourseName") & "' SELECTED>" Response.Write oRs("CourseName") & "</Option>" oRs.MoveNext else Response.Write "<OPTION VALUE = '" & oRs ("CourseName") & "'>" Response.Write oRs("CourseName") & "</Option>" oRs.MoveNext end if loop %> </SELECT> -------------------------------------------------------------------------------- From there I want the selected values to be submitted in a form and displayed. I have managed to do this using the <%=Request.Form("courses")%> My problem is that it displays it as a total string.. I need to store each individual value selected in a seperate field in another database table, but at the moment I can only save it in one field... Please, If anyone has any ideas.. Thanks |
|
#2
|
||||
|
||||
|
is it displaying like this ?
Code:
value1, value2, value3, etc... If so, then just split the values, like this Code:
values = Request.Form("courses")
newValues = Split(values, ",")
For i = 0 To UBound(newValues)
Response.write(newValues(i) & "<br>")
Next
|
|
#3
|
|||
|
|||
|
Hi,
You can set up an array <% 'define your variables Dim courseArr, counter 'create the array from the passed form variable courseArr = Split(request.form("courses"), ", ", -1, 1) 'loop through array printing each to screen For counter = 0 To UBound(courseArr) response.write("Selection number " & counter & " was " & courseArr(counter) & " <br>") Next 'counter %> hope this helps, |
|
#4
|
|||
|
|||
|
Thanks guys,
this works perfectly |
![]() |
| Viewing: ASP Free Forums > Database > SQL Development > Multiple Selections from a list box |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|