Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>This script below should put you on the right track perhaps?</p> <p>You can keep this html the same (though I changed the method to POST):</p> <pre><code>&lt;form method="POST" id="subscribeForm"&gt; &lt;fieldset id="cbgroup"&gt; &lt;div&gt;&lt;input name="list" id="list0" type="checkbox" value="newsletter0" &gt;zero&lt;/div&gt; &lt;div&gt;&lt;input name="list" id="list1" type="checkbox" value="newsletter1" &gt;one&lt;/div&gt; &lt;div&gt;&lt;input name="list" id="list2" type="checkbox" value="newsletter2" &gt;two&lt;/div&gt; &lt;/fieldset&gt; &lt;input name="submit" type="submit" value="submit"&gt; &lt;/form&gt; </code></pre> <p>and this javascript validates</p> <pre><code>function onSubmit() { var fields = $("input[name='list']").serializeArray(); if (fields.length === 0) { alert('nothing selected'); // cancel submit return false; } else { alert(fields.length + " items selected"); } } // register event on form, not submit button $('#subscribeForm').submit(onSubmit) </code></pre> <p>and you can find a <a href="http://jsfiddle.net/evildonald/qsBKy/1/" rel="nofollow noreferrer">working example of it here</a></p> <p><strong>UPDATE (Oct 2012)</strong><br> Additionally it should be noted that the checkboxes <em>must</em> have a "name" property, or else they will not be added to the array. Only having "id" will not work.</p> <p><strong>UPDATE (May 2013)</strong><br> Moved the submit registration to javascript and registered the submit onto the form (as it should have been originally)</p> <p><strong>UPDATE (June 2016)</strong><br> Changes == to ===</p>
    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.
    3. 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