0

I'm trying to make my div#products not moving when (a) link is clicked. Already tried "preventDefault" or "return false" and it doesn't work at all, page still refreshing or the (a) link become freezing when clicked (product can not be added to database). Can anyone show me how to write it? Just write it into my code here.

<!-- This is my index.php -->

    <!doctype html>
    <?php include ("functions/functions.php"); ?>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Learning</title>
    <link rel="stylesheet" href="styles/style.css" type="text/css" media="all" />
    <script src="js/jquery-3.0.0.min.js"></script>

    <script type = "text/javascript" language = "javascript">
       $(document).ready(function() {
          $("a").click(function(event){
             event.preventDefault();
             alert( "Added to cart!" );
          });
       });
    </script>

</head>

<body>
    <div id="container">
        <div id="header"> </div>

            <div id="products">
                <?php getPro(); ?>
            </div>

        <div id="footer"> </div>
    </div>
</body>

//This is my functions.php

function getPro(){
    if(!isset($_GET['cat'])){
        if(!isset($_GET['brand'])){

    global $con;
    $get_pro = "select * from products";
    $run_pro = mysqli_query($con, $get_pro);
    while ($row_pro=mysqli_fetch_array($run_pro)){
        $pro_id = $row_pro['product_id'];
        $pro_cat = $row_pro['product_cat'];
        $pro_brand = $row_pro['product_brand'];
        $pro_title = $row_pro['product_title'];
        $pro_image = $row_pro['product_image'];

        echo "<div id='single_product'>
                    <h1>$pro_title</h1>
                    <img src='admin_area/product_images/$pro_image' width='135' height='150'/>
                    <a href='?add_cart=$pro_id'>Add2Cart</a>
                    </div>
                </div>";
    }
        }
    }
}
Sean
  • 1
  • 1

0 Answers0