jQuery/PHP Select checkboxes from $_SESSION variable
<p>I'm not sure if I'm doing this completely wrong, but I'm hoping what I'm trying to do is possible.</p>

<p>I have an existing ajax jquery function that saves the "selected" checkboxes from a user and stores them in $_SESSION['order_items'][index]['cheeseids'][]; When a user goes to recall this "item", I'd like to have the same checkboxes "selected" as before. See example below:</p>

<pre><code>[order_items] =&gt; Array
    (
        [1] =&gt; Array
            (
                [cheeseids] =&gt; Array
                    (
                        [0] =&gt; 1
                        [1] =&gt; 2
                        [2] =&gt; 4
                    )
</code></pre>

<p>My "change/restore" jquery function uses the following variables to get the index number:</p>

<pre><code>var productIDValSplitter   = (this.id).split("_");
var productIDVal       = productIDValSplitter[1]; 
</code></pre>

<p>The function I'm trying to use to "re-select" boxes 1, 2, 4 (from cheeseids array) is not working (it is inside my jQuery function). It actually causes the entire jQuery code to not work:</p>

<pre><code>&lt;?php
foreach($_SESSION['order_items'] as $key =&gt; $value)
{
?&gt;

var idnum = &lt;?php echo $value['&lt;script type="text/javascript"&gt;productIDVal&lt;/script&gt;']['cheeseids']  ?&gt;;
$("div.cheesebox input[type=checkbox]").eq(" + idnum + ").attr("checked", "checked");

&lt;?php
}
?&gt;
</code></pre>

<p>JS Output:</p>

<pre><code>var idnum = ;
$("div.cheesebox input[type=checkbox]").eq(" + idnum + ").attr("checked", "checked");

var idnum = ;
$("div.cheesebox input[type=checkbox]").eq(" + idnum + ").attr("checked", "checked");
</code></pre>

<p>Entire JS/jQuery function that I'm adding the PHP too:</p>

<pre><code>$("#basketItemsWrap li img.change").live("click", function(event) {
        var productIDValSplitter   = (this.id).split("_");
        var productIDVal       = productIDValSplitter[1];  
        $("#notificationsLoader").show();
        $.ajax({  
        type: "POST",  
        url: "includes/ajax/functions.php",
        data: { productID: productIDVal, action: "deleteFromBasket"},  
        success: function(theResponse) {
          $("div#order_qty input").attr('value', $("#order_" + productIDVal + " #order_qty").text());
          $("div#order_listprice input#price1").attr('value', $("#order_" + productIDVal + " #order_listprice").text().replace("$", ""));
          $("div#order_price input#discprice1").attr('value', $("#order_" + productIDVal + " #order_price").text().replace("$", ""));
          $("div#order_price input#itemprice1").attr('value', $("#order_" + productIDVal + " #order_itemprice").text().replace("$", ""));


          //The following functions restore the order details in the select menus, checkboxes, and radio buttons
          //Restores the item selected
          for(var i = 0; i &lt; $("#item1 option").size(); i++)
          {
            if($("#order_" + productIDVal + " #order_item").text() == $("#item1 option:eq("+i+")").text())
            {
              $("#item1 option:eq("+i+")").attr("selected", "selected");
              //$("#item1").val(i);
              CalcPrice(1);
            }
          }

          //Restores the promotion selected
          for(var i = 0; i &lt; $("#promo1 option").size(); i++)
          {
            if($("#order_" + productIDVal + " #order_promo").text() == $("#promo1 option:eq("+i+")").text())
            {
              $("#promo1 option:eq("+i+")").attr("selected", "selected");
              //$("#promo1").val(i);
              CalcPromo(1);
            }
          }

            &lt;?php foreach($_SESSION['order_items'][1]['cheeseids'] as $id): ?&gt;
             $("div.cheesebox input[type=checkbox]#&lt;?php echo $id;?&gt;").attr("checked", "checked");
          &lt;?php endforeach; ?&gt;
          //Restores the cheese options selected



          // $('div.cheesebox input[type=checkbox]').size(); i++)

          //$('div.cheesebox input[type=checkbox]').eq(1).attr('checked', 'checked');


          $("#order_" + productIDVal).hide("slow",  function() {$(this).remove();Calc();});
          $("#notificationsLoader").hide();
        }  
        }); 
      });
</code></pre>

<p>PHP/HTML code to generate the checkboxes:</p>

<pre><code>&lt;?php
        //Display all "cheese" options in a checkbox group
          foreach($_SESSION['ingr_cheese'] as $key =&gt; $value)
          {
              echo "&lt;div class=\"cheesebox\" style=\"float:left; width:175px; margin-bottom:7px;\"&gt;";
              echo "&lt;input type=\"checkbox\" name=\"cheese1\" id=\"cheese1\" class=\"cheeseCheck\" value=\"".$key."\"&gt;&amp;nbsp;&lt;label for=\"cheese1\"&gt;".$value['cheese']."&lt;/label&gt;&lt;/br&gt;";
              echo "&lt;/div&gt;";
          }
        ?&gt;
</code></pre>
