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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Multipart enctype and checkbox arrays

Status
Not open for further replies.

travisbrown

Technical User
Dec 31, 2001
1,016
I have a form I need to submit as a multipart enctype. Problem is, I'd usually retrieve all the values from a checkbox group as a comma-delimited array. When i use multipart, I only get the first value (using Upload.Form with Persists ASP Upload)
Code:
Request.form(“ingredient_id”)
ingredient_id = 2,3,5,8,7,33
With ASPUpload, after changing the enctype, I only get the first value
Code:
Upload.Form("ingredient_id")
ingredient_id = 2
Is there a way to collate the values so i can process them with a loop?

The BinaryRead on the post looks like this

Code:
7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 1 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 3 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 4 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 8 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 5 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 6 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 7 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 9 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 36 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 85 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 105 -----------------------------7d7d0301065e Content-Disposition: form-data; name="ingredient_id" 126 -----------------------------7d7d0301065e--
 
In the meantime, and maybe this is the best way to do it anyways, I created a string with javascript. I'd rather do this serverside, but...

Code:
<script type="text/javascript">
function CollateIngredients() {
	var cbCollection = document.forms[0].elements['ingredient_id'];
	var checkboxarray
	var counter = 0
	for ( var i = 0; i < cbCollection.length; i++ ) {
		if ( cbCollection[i].checked )  {
			if ( counter == 0 ) 
				{checkboxarray = cbCollection[i].value;}
			else 
				{checkboxarray = checkboxarray + ',' + cbCollection[i].value;}
				counter = counter + 1;
		}
	}
	
	document.getElementById('product_ingredients').value = checkboxarray;
	alert(document.getElementById('product_ingredients').value);
}
</script>

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top