Revision: 27465
Initial Code
Initial URL
Initial Description
Initial Title
Initial Tags
Initial Language
at June 9, 2010 20:07 by verostudios
Initial Code
// implodeFormArray(form name : String, form element name : String, delimiter : String); function implodeFormArray(f, e, del) { var form = document.forms[f]; if (typeof(form.elements[e].value) != "undefined") { if (form.elements[e].checked) return form.elements[e].value; else return ''; } else { var output = ''; var len = form.elements[e].length; for(var i=0;i<len;i++) { if (form.elements[e][i].checked) { output+= (output == '' ? '':del) + form.elements[e][i].value; } } return output; } }
Initial URL
Initial Description
I frequently pass an array of elements from an HTML form to PHP, normally a list of checkboxes for removing database records. This will loop through an array of checkbox's with the same name & build a delimited string from the checked values. After I have the values in a delimited string I normally have a hidden field which holds the string & explode it on the PHP side.
Initial Title
Implode Form Element Array
Initial Tags
form, html, array
Initial Language
JavaScript