/ Published in: JavaScript
                    
                                        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.
                
                            
                                Expand |
                                Embed | Plain Text
                            
                        
                        Copy this code and paste it in your HTML
 // 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; } }
Comments
                    Subscribe to comments
                
                