Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>You should use a associative array instead of an array, so that you can look up the data based on the name as a string instead of trying to find the variable. All objects in Javascript are associative arrays, so just put the data in an object.</p> <p>Also:</p> <ul> <li>Create the <code>mygraphs</code> array inside the event handler, otherwise it can not shrink when you uncheck options.</li> <li>Catch the click on the checkboxes inside the form, not on the form itself.</li> <li>Put a <code>label</code> tag around the checkbox and it's label, that way the label is also clickable.</li> <li>You don't need an index variable to put values in the <code>mygraphs</code> array, just use the <code>push</code> method to add items to it.</li> </ul> <p><a href="http://jsfiddle.net/cCukJ/" rel="nofollow">http://jsfiddle.net/cCukJ/</a></p> <p>Javascript:</p> <pre><code>$(function() { Comment = [['2011-01-29',7695],['2011-02-02',19805]]; WallPost = [['2011-01-29',11115],['2011-02-02',8680]]; Likes = [['2011-01-29',5405],['2011-02-02',10930]]; var seriesre = { 'Comment': Comment, 'WallPost': WallPost, 'Likes': Likes }; $("#testCheck :checkbox").click(function() { var mygraphs = []; $("#testCheck :checked").each(function() { mygraphs.push(seriesre[$(this).val()]); }); alert("["+mygraphs+"]"); }); }); </code></pre> <p>HTML:</p> <pre><code>&lt;div class="activity"&gt; &lt;form method="POST" id="testCheck" name="myform"&gt; &lt;label&gt; Likes &lt;input type="checkbox" value="Likes" name="box2"&gt; &lt;/label&gt; &lt;label&gt; Comments &lt;input type="checkbox" value="Comment" name="box3"&gt; &lt;/label&gt; &lt;label&gt; Wall Post &lt;input type="checkbox" value="WallPost" name="box4"&gt; &lt;/label&gt; &lt;/form&gt; &lt;/div&gt; </code></pre>
    singulars
    1. This table or related slice is empty.
    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.
    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