title: How can I pass the value coming from a jQuery variable to PHP?
body: <p>The webpage I am working on has many rows of data with checkboxes at the end.</p>
  
  <p>Sample is:</p>
  
  <p><img src="https://i.stack.imgur.com/cD5PX.png" alt="checkbox row layout"></p>
  
  <p>So I am collecting the Page IDs of each row when the user checks the checkbox.</p>
  
  <p>But how do I pass the collected data from jQuery to PHP? </p>
  
  <p>So far I have the following:</p>
  
  <p>jQuery:</p>
  
  <pre><code>var collectionOfPages = [];
  
  (function ( $ ){
      $.fn.addCheckBox = function()
      {
          $("#submitAddID").on("click", this, function()
          {
                 alert(collectionOfPages);
          });
  
          $("#addCheckBoxes input[type='checkbox']").click(function() 
          {      
              if($(this).prop('checked') == true) 
              {
                   $('#addCheckBoxes :checked').each(function() 
                   {
                      collectionOfPages.push($(this).val());
                   }); 
              } 
              else
              {                              
                 //TODO
              }   
          });
      };   
  })(jQuery);
  </code></pre>
  
  <p>PHP:</p>
  
  <pre><code>&lt;form name="frmAdd" id="addCheckboxForm" method="post" action="index.php"&gt;
      &lt;input type="hidden" name="useridHidden" id="useridHidden"/&gt;
      &lt;input type="hidden" name="pagesHidden"  id="pagesHidden" /&gt;
  &lt;/form&gt;
  
  &lt;table id="checkboxTables" cellpadding="10" cellspacing="1"&gt;
      &lt;thead&gt;
              &lt;tr&gt;
                  &lt;th&gt;&lt;strong&gt;Page ID&lt;/strong&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;strong&gt;Page Name&lt;/strong&gt;&lt;/th&gt;
                  &lt;th&gt;&lt;strong&gt;Action&lt;/strong&gt;&lt;/th&gt;
              &lt;/tr&gt;
      &lt;/thead&gt;
  
       &lt;tbody&gt;
               &lt;tr id="addCheckBoxes"&gt;
                   &lt;td&gt;&lt;?php echo $row["PAGEID"]; ?&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;?php echo $row["PAGENAME"]; ?&gt;&lt;/td&gt;
                   &lt;td&gt;&lt;input type="checkbox" name="chkboxAdd" $row["PAGEID"]; ?&gt;"&gt;Add&lt;/td&gt;
               &lt;/tr&gt;
       &lt;/tbody&gt;
  
  &lt;/table&gt;
  
  &lt;button type="button" name="submitAdd" id="submitAddID"&gt;Submit &lt;/button&gt;
  </code></pre>
  
  <p>So I would like to pass the values coming from the jQuery variable</p>
  
  <pre><code>collectionOfPages
  </code></pre>
  
  <p>to the PHP variable: </p>
  
  <pre><code>$_POST['pagesHidden]
  </code></pre>
  
  <p>which was created inside the </p>
  
  <pre><code>&lt;input type="hidden" name="pagesHidden"  id="pagesHidden" /&gt;
  </code></pre>
  
  <p>Thank you in advance.</p>