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.
<script>
$('#economy').append('<div id="element">'+
'<img src=<?php echo $row['photo'] ?> class="bike-img">'+
'<p class="bike-desc" style="font-size:18px;"><?php echo $row['name'] ?></p>'+
'<?php if(in_array($row['name'], $bikes)) { ?>'+
'<div id= <?php echo $row['name']?> class="availability notavailable"><p class="bike-desc">Already Booked</p></div>'+
'<?php } else {?>'+
'<div id= <?php echo $row['name']?> class="availability available" onclick="book(this.id)"><p class="bike-desc">Book Now</p></div>'+
'<?php } ?>'+
'</div>');
</script>
The function after onclick:
<script>
function book(id){
document.cookie = "bike = " + id;
<?php
$_SESSION['from']=$_GET['from'];
$_SESSION['to']=$_GET['to'];
$_SESSION['pickup']=$_GET['pickup'];
$_SESSION['bike']=$_COOKIE['bike'];
---header("Location:bikebooking.php");---
?>
window.location.href = "bikebooking.php";
});
</script>
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.