From cc7f3ef768856f0c7726453276f33c74e203e86b Mon Sep 17 00:00:00 2001 From: Ralf Becker Date: Thu, 13 Sep 2007 12:30:57 +0000 Subject: [PATCH] new function to set certain values in a multiselection (div with checkboxes) --- etemplate/js/etemplate.js | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/etemplate/js/etemplate.js b/etemplate/js/etemplate.js index e301a1875d..211a640055 100644 --- a/etemplate/js/etemplate.js +++ b/etemplate/js/etemplate.js @@ -253,3 +253,26 @@ function get_selected(form,suffix) { } return selected; } + +// set certain comma-separated values in a multiselection (div with checkboxes, used as replacement for a multiselection) +function set_multiselection(name,values,reset) +{ + //alert("set_multiselection('"+name+"','"+values+"',"+reset+")"); + checkboxes = document.getElementsByName(name); + div = document.getElementById(name.substr(0,name.length-2)); + div_first = div.firstChild; + values = ','+values+','; + for (var i = 0; i < checkboxes.length; i++) { + checkbox = checkboxes[i]; + value = values.indexOf(','+checkbox.value+',') >= 0; + if (reset || value) { + //alert(checkbox.name+': value='+checkbox.value+', checked='+checkbox.checked+' --> '+value); + checkbox.checked = value; + if (value && checkbox.parentNode != div_first) { + br = checkbox.parentNode.nextSibling; + div.insertBefore(div.removeChild(checkbox.parentNode),div_first); + div.insertBefore(div.removeChild(br),div_first); + } + } + } +}