title: read javascript cookie with PHP on the same page
body: <p>I have a page, return.php.  It has a line of HTML as follows:</p>
  
  <pre><code>&lt;td&gt;&lt;a href="#" dataP="&lt;?= $partNumber[$x] ?&gt;" onclick="popup(this)"&gt;&lt;?= substr($avgCost[0],0,6) ?&gt;&lt;/a&gt;&lt;/td&gt;
  </code></pre>
  
  <p><code>onclick</code>, this calls the following popup function:</p>
  
  <pre><code>function popup(windowname) {  
    document.cookie = 'popupPartNumber='+windowname.getAttribute("dataP")+'; expires=Wed, 1 Jan 2070 13:47:11 UTC; path=/'
    var x = document.cookie;
    console.log(x);    
    windowname = 'popUpDiv';
    blanket_size(windowname);
      window_pos(windowname);
      toggle('blanket');
      toggle(windowname);
  
  }
  </code></pre>
  
  <p>on this same page, this loads:</p>
  
  <pre><code>&lt;div id="blanket" style="display:none;"&gt;&lt;/div&gt;
    &lt;div id="popUpDiv" style="display:none;""&gt;
    &lt;a href="#"" onclick="popup(this)"&gt;&lt;img src="/img/close.png"&gt;&lt;/a&gt;
  &lt;?php
    $popupPartNumber  = $_COOKIE['popupPartNumber'];
    echo "&lt;pre&gt;";
    echo htmlentities($_COOKIE['popupPartNumber'], 3, 'UTF-8');
    echo "&lt;/pre&gt;";
  ?&gt;
  
  &lt;/div&gt;
  </code></pre>
  
  <p>When I start this out and I click on the HTML link, I get a console.log output that says:</p>
  
  <pre><code>PHPSESSID=cvbt1gvisul27nccenaeum1hh0; popupPartNumber=123456789
  </code></pre>
  
  <p>but my php echo output says: <code>null</code></p>
  
  <p>Why is the cookie that I'm setting correctly in javascript not available to php?</p>
  
  <h1>Update</h1>
  
  <p>I changed <code>return.php</code> to say:</p>
  
  <pre><code>$popupPartNumber = $_POST['popupPartNumber']; //part number line
    echo "&lt;pre&gt;"; 
    echo "value is: " . $popupPartNumber ;
    echo "&lt;/pre&gt;";
  </code></pre>
  
  <p>and I changed the script to read:</p>
  
  <pre><code>var x = windowname.getAttribute("dataP");
  
    $.ajax({
        type: 'POST',
        url: 'return.php',
        data: {popupPartNumber:x},        
          success:function(data){
            alert(data);
            }
          });
  
  console.log(x); //outputs the correct number.
  </code></pre>
  
  <p>This isn't working though... I still get no value to the php variable.</p>