Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You will need a script that converts the checkbox input into whatever format (say, a string of words separated by spaces) was needed for the original tags input. Here is an example script that would both insert the checkboxes to the page underneath the original input and put the resulting values into the original field, ensuring it gets posted the same way. (You could then hide the original field if you don't want it displayed.) <a href="http://jsfiddle.net/zLVTp/8/" rel="nofollow">http://jsfiddle.net/zLVTp/8/</a></p> <pre><code>var tags = ['cows', 'sheep', 'dogs'], inp, label, ch = document.createElement('fieldset'), f = document.getElementById('tagField'); // ^ The original input has id=tagField f.readOnly = true; for (var i = 0; i &lt; tags.length; i++) { inp = document.createElement('input'); label = document.createElement('label'); label.innerHTML = tags[i]; label.htmlFor = 'tag_' + tags[i]; inp.type = "checkbox"; inp.name = "tagSet"; inp.className = 'tagCBs'; inp.value = tags[i]; inp.id = 'tag_' + tags[i]; ch.appendChild(inp); ch.appendChild(label); inp.onchange = (function() { var th = inp; return function() { var sp, r = []; if (th.checked &amp;&amp; f.value.indexOf(th.value) == -1) { if (f.value == '') f.value = th.value; else f.value += ' ' + th.value; } else if (!th.checked) { sp = f.value.split(' '); for (var j = 0; j &lt; sp.length; j++) { if (sp[j] != th.value) r.push(sp[j]); } f.value = r.join(' '); } } })(); } f.parentNode.appendChild(ch);​ </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload