Good day i have an html div written below.
.SubmitOrder { height: 60px; width: 200px; margin-top: 10px; margin-right: 30px; float: right; background: #C40514; text-align: center; display: block; }
<head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> </head> <div class="SubmitOrder"> <?php echo "Total: ".$totalPrice."<br> Pay Now!" ?> <script> $('.SubmitOrder').on('click', function() { window.location.replace(<?php echo "home.php?account_id=$accountid" ?>); }) </script> </div>
But upon clicking the div it does not redirect me to the link. Am I doing something wrong?
It will be better to place your script inside the head
part using the ready
function will assure that all the targeted elements inside your script are loaded.
NOTE : You must also wrap the new link <?php echo "home.php?account_id=$accountid" ?>
in single quotes ''
.
window.location.replace('<?php echo "home.php?account_id=$accountid" ?>');
.SubmitOrder { height: 60px; width: 200px; margin-top: 10px; margin-right: 30px; float: right; background: #C40514; text-align: center; display: block; }
<html> <head> <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <script> $(function() { $('.SubmitOrder').on('click', function() { window.location.replace('<?php echo "home.php?account_id=$accountid" ?>'); }); }); </script> </head> <body> <div class="SubmitOrder"> Total: 1000$ <br> Pay Now! </div> </body> </html>
try this for javascript
<div class="SubmitOrder">
<?php echo "Total: ".$totalPrice."<br> Pay Now!" ?>
</div>
<script>
$('.SubmitOrder').on('click', function() {
window.location.replace(<?php echo "home.php?account_id=$accountid" ?>);
})
</script>
move script tag out of div with class SubmitOrder
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.