I want when someone clicks this link to go first on myfunction that I have in JS and after that follow the href function that exists in <a>
tag. The problem is that it follows first the href and I can't pass the variable I want from the js function.
here is my code:
PHP
echo '<a href="category.php?id=' . $_SESSION['id'] . '" onclick="myFunction();">
<div class="icon-lock">
<img src="/test/images/lock.png" alt="Locked Button" width="35" height="35" border="0">
</div>';
echo '</a>';
JS
<script>
function myFunction() {
$.ajax({
type: "POST",
data: {id: "1"},
url: "category.php"
});
}
</script>
I am very confused on how href and myfunction will work in order to print
$id=$_POST['id'];
echo $id;
in php after the page has been reloaded...
Any thoughts?