Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multi Select not sending all selected items to DB

Status
Not open for further replies.

bhewi

Programmer
Dec 16, 2003
12
0
0
US
I have a multi select form that retrieves a list of users from a database and upon clicking on them moves them from the left box to the right box. I then want to upload a file and a description of the file up to the database (access) for each user. I have everything working except when I select more than one user it only uploads the first one on the list. I fairly new at this so any help would be really appreciative.

Thanks
Bryon

Here is the code from the form:

<FORM NAME=&quot;userslist&quot; METHOD=&quot;POST&quot; ENCTYPE=&quot;multipart/form-data&quot;
ACTION=&quot;ado_upload.asp?<% = PID %>&quot;
OnSubmit=&quot;return ShowProgress();&quot;>

<CENTER>
<TABLE border=1>
<TR><TD>
<table>
<tr>
<td bgcolor=&quot;#cccccc&quot; align=&quot;middle&quot; ><b>Available Users</b></td>
<td></td>
<td bgcolor=&quot;#cccccc&quot; align=&quot;middle&quot; ><b>Selected Users</b></td>
</tr>
<tr>
<td align=&quot;left&quot;><!-- onchange=&quot;moveit();&quot; -->
<select name=&quot;menuitems1&quot; onchange=&quot;moveit();&quot; style=&quot;WIDTH: 300px&quot; size=&quot;10&quot; multiple>
<%
'Loop through the recordset adding each customer to the combo box
Do While Not objRS.EOF
%>
<option value=&quot;<%=objRS(&quot;UserName&quot;)%>&quot;>
<%=objRS(&quot;CustName&quot;)%> -- <%=objRS(&quot;CompanyName&quot;)%></option>

<%
objRS.MoveNext
Loop

'Close and dereference database objects
objRS.Close
Set objRS = Nothing
%>

</select>
</td>
<td align=&quot;middle&quot;>
<input type=&quot;button&quot; tagName=&quot;BUTTON&quot; onclick=&quot;removefromcombo();&quot; value=&quot; < < Remove&quot; id=&quot;submit2&quot; name=&quot;submit2&quot; style=&quot;FONT-WEIGHT: bold&quot;>
</td>
<td align=&quot;left&quot;>
<select name=&quot;UserName&quot; id=&quot;UserName&quot; style=&quot;WIDTH: 300px&quot; size=&quot;10&quot; multiple>

</select></td></tr><tr><td colspan=&quot;3&quot;>

File:  <INPUT TYPE=FILE NAME=&quot;THEFILE&quot; size=&quot;20&quot;></p>
<P>
Description:  <TEXTAREA NAME=&quot;DESCR&quot; rows=&quot;1&quot; cols=&quot;31&quot;></TEXTAREA><P>
<INPUT TYPE=SUBMIT VALUE=&quot;Upload!&quot;></FORM>

----------------------------------
Here is the code from the page that places the data in the DB:
<%
Set Upload = Server.CreateObject(&quot;Persits.Upload&quot;)
Upload.ProgressID = Request.QueryString(&quot;PID&quot;)

' we use memory uploads, so we must limit file size
Upload.SetMaxSize 40000000, True

' Save to memory. Path parameter is omitted
Count = Upload.Save

' Obtain file object
Set File = Upload.Files(&quot;THEFILE&quot;)

If Not File Is Nothing Then

Connect = &quot;DSN=aspupload&quot;

' Use ADO Recordset object
Set rs = Server.CreateObject(&quot;adodb.recordset&quot;)

' Reopen recordset to insert file
rs.Open &quot;MYIMAGES&quot;, Connect, 2, 3

rs.AddNew
rs(&quot;image_blob&quot;) = File.Binary
rs(&quot;filename&quot;) = File.FileName
rs(&quot;filesize&quot;) = File.Size
rs(&quot;description&quot;) = Upload.Form(&quot;DESCR&quot;)
rs(&quot;UserName&quot;) = Upload.Form(&quot;UserName&quot;)
rs.Update

Response.Write &quot;File saved.&quot;
Else
Response.Write &quot;File not selected.&quot;
End If
%>
 
I was wondering if anyone got any workaround to the problem.
This seems to be an issue with the form enctype, which, when set to multipart/form-data, results in sending only the first option selected. When not set at all (i.e. default enctype), it does pass all options selected (comma separated values as stated before).

I came across the same problem and can't seem to find any info on this. Also I do need to set enctype=&quot;multipart/form-data&quot; as I need to upload a file aswell as some user input.

João.
 
Nope, I did a work around involving 5 drop down boxes. I just finally gave up on it. If you need anything let me know, I'll help out best I can.

Bryon
 
Thanks, but I finally solved it with javascript, using an hidden field and the onBlur event for the select.
Basically, I'm processing the values client-side before submitting the form

this goes in the <head> section:
Code:
<script language=&quot;JavaScript&quot;>
function getValue(){
	var obj1 = document.[formname].[selectname] // replace values inside [] with your element names
	var obj2 = document.[formname].[hiddenname] // same as above
	var valor = &quot;&quot;
	for(var i = 0; i < obj1.length; i++){
		if(obj1.options[i].selected){
			valor += obj1.options[i].value + &quot;,&quot;
		}
	}
	obj2.value = valor
}
</script>
and add the following to the select:

<select... onBlur=&quot;getValue();&quot;>

I only tested this with IE6 and although it should work with versions 4+ and NN4+, I haven't tested it properly.

João.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top