title: Redirect to another page with information on clicking a div
body: <p>I am appending divisions to my html page dynamically using jquery append method. This division consists of a sub division. I want to redirect to another page with some information using sessions when the div is clicked. But the page is being redirected to my target page without even clicking on it.</p>
  
  <pre><code>&lt;script&gt;
      $('#economy').append('&lt;div id="element"&gt;'+
                              '&lt;img src=&lt;?php echo $row['photo'] ?&gt; class="bike-img"&gt;'+
                              '&lt;p class="bike-desc" style="font-size:18px;"&gt;&lt;?php echo $row['name'] ?&gt;&lt;/p&gt;'+
                              '&lt;?php if(in_array($row['name'], $bikes)) { ?&gt;'+
                              '&lt;div id= &lt;?php echo $row['name']?&gt; class="availability notavailable"&gt;&lt;p class="bike-desc"&gt;Already Booked&lt;/p&gt;&lt;/div&gt;'+
                              '&lt;?php } else {?&gt;'+
                              '&lt;div id= &lt;?php echo $row['name']?&gt; class="availability available" onclick="book(this.id)"&gt;&lt;p class="bike-desc"&gt;Book Now&lt;/p&gt;&lt;/div&gt;'+
                              '&lt;?php } ?&gt;'+
                              '&lt;/div&gt;');
      &lt;/script&gt;
  </code></pre>
  
  <p>The function after onclick:</p>
  
  <pre><code>&lt;script&gt;
  function book(id){
  document.cookie = "bike = " + id;
  &lt;?php
      $_SESSION['from']=$_GET['from'];
      $_SESSION['to']=$_GET['to'];
      $_SESSION['pickup']=$_GET['pickup'];
      $_SESSION['bike']=$_COOKIE['bike'];
      ---header("Location:bikebooking.php");---   
  ?&gt;
  window.location.href = "bikebooking.php";
  });
  &lt;/script&gt;
  </code></pre>
  
  <p>I even tried using jquery but I am facing the same problem my main page is automatically redirecting to the direct page without any clicks.</p>