title: JavaScript Popup window display inside PHP IF Function without onClick
body: <p>I was following a tutorial on YouTube about how to display a popup box after the click of a button. It was fairly simple but now I want to twist things a little bit. I want to display the markup inside a PHP IF function. </p>
  
  <p>I believe that creating a JavaScript function would be the road to follow but I am not proficient in JavaScript/jQuery as I am only starting with it now. 
  I want to display the following markup should my PHP IF function equate to TRUE</p>
  
  <pre><code> &lt;div id="popup-box" class="popup-position"&gt;
      &lt;div class="popup-wrapper"&gt; &lt;!-- move away from screen and center popup --&gt;
          &lt;div class="container"&gt; &lt;!-- backgorund of pop up --&gt;
              &lt;h2&gt;Pop box&lt;h2&gt;
              &lt;p&gt;&lt;a href="javascript:void(0)"&gt;Close popup&lt;/a&gt;&lt;/p&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  </code></pre>
  
  <p>The following JavaScript function is used in the tutorial that I was following. It works perfectly when it is triggered by onClick.</p>
  
  <pre><code>&lt;script&gt;
  function toggle_visibility(id) {
     var e = document.getElementById(id);
     if(e.style.display == 'block')
        e.style.display = 'none';
     else
        e.style.display = 'block';
  }
  &lt;/script&gt;
  </code></pre>
  
  <p>I have the following PHP script</p>
  
  <pre><code>function cart($userEmailAdd){
      global $dbc; // database connection variable
      /* 
       Verify if the product that is being added already exists in the cart_product table.
       Should it exist in the cart then display popup box with an appropriate 
       message. 
  
       Otherwise, add the product to cart_product
      */
      if(isset($_GET['cart'])){
      $productID = $_GET['cart'];
  
          $queryCheckCart = "SELECT * from cart_product WHERE emailOfCustomer = '$userEmailAdd' AND  cpProductid = '$productID'"; 
  
          $executeCheckCart = mysqli_query($dbc, $queryCheckCart) or die (mysqli_error($dbc));
  
          if(mysqli_num_rows($executeCheckCart) &gt; 0 ){
  
          /* IF MYSQLI_NUM_ROWS is greater than zero then 
          it means that the product already exists in the cart_product table. 
          Then display following markup*/
  
              ?&gt;
              &lt;div id="popup-box" class="popup-position"&gt;
                  &lt;div class="popup-wrapper"&gt; &lt;!-- move away from screen and center popup --&gt;
                      &lt;div class="container"&gt; &lt;!-- backgorund of pop up --&gt;
                          &lt;h2&gt;Pop box&lt;h2&gt;
                          &lt;p&gt;&lt;a href="javascript:void(0)"&gt;X&lt;/a&gt;&lt;/p&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt; &lt;!-- --&gt;
              &lt;?php 
  
          } else {
  
              $query = "INSERT INTO cart..." ;
              // rest of script continues after this for insertion of the product
  </code></pre>
  
  <p>How do I go about using the same function or a similar one without using onClick  to display the markup?  </p>