title: How to pass jQuery variables to PHP variable?
body: <p>How do you pass a variable from jQuery to PHP without a page refresh? When I click on a checkbox I would like to pass a variable from jQuery to PHP. I am also using formdialog.</p>
  
  <p>My PHP code</p>
  
  <pre><code>&lt;?php
  echo "&lt;input name='opendialog' type='checkbox' class='opendialog' onclick='countChecked()' value=".$taskid." ?&gt;" /&gt; &lt;/td&gt;"
  ?&gt;
  </code></pre>
  
  <p>my javascript code</p>
  
  <pre><code>function countChecked() {
    var n = $("input:checked").length;
  
    var allVals = [];
     $('input:checkbox:checked').each(function() {
     allVals.push($(this).val());
  
     });
     $('.sel').text(allVals+' ');
     $('.select1').val(allVals);
     alert(allVals);
  
      &lt;?php $taskidj=$rowtask['taskID'];
     // echo "aaa...".$rowtask['taskID']; ?&gt;     
  
  }
  
  $(":checkbox").click(countChecked);
  
  
  // my jquery code
  
  
          $('.mydialog').dialog({
  
              bgiframe: true,
              autoOpen: false,
              modal: true,
              width: 700,
              height:500,
              resizable: false,
              open: function(){closedialog = 1;$(document).bind('click', overlayclickclose);},
              focus: function(){closedialog = 0;},
              close: function(){$(document).unbind('click');},
              buttons: {
                  Submit: function(){
                  var bValid = true;
              //  allFields.removeClass( "ui-state-error" );
  
              //  bValid = bValid &amp;&amp; checkLength( name, "username", 3, 16 );
  
  
  
              //  bValid = bValid &amp;&amp; checkRegexp( name, /^[a-z]([0-9a-z_])+$/i, "Username may consist of a-z, 0-9, underscores, begin with a letter." );
  
  
  
  
  
                  if ( bValid ) {
  
                          processDetails();
  
                          return false;
  
                  }
  
  
                  },
                  Cancel: function() {
                      $( this ).dialog( "close" );
                      $('input[name=opendialog]').attr('checked', false);
                  }
              }
          });
  
      $('.opendialog').click(function() {
              $('.mydialog').dialog('open');
              closedialog = 0;
          });
  </code></pre>