Im into HTML/JS/PHP for 2 Months now and I have 2 problems in my code where the page reloads / jumps to top but it shouldnt in my opinion.
In the first snippet im just trying to click the image so I can send a request to my database, but the page shouldnt move at all.
function favorite(identifier)
{
$.ajax(
{
url:"favorite.php",
type:"POST",
data:
{
id: $(identifier).data('option')
},
success:function(data)
{
$(".container").html(data);
}
});
};
<input type="image" class="favorite-image" src="https://upload.wikimedia.org/wikipedia/commons/thumb/5/52/Heart_icon_red_hollow.svg/800px-Heart_icon_red_hollow.svg.png" data-option="<?php echo $row['id']?>" onclick="return favorite(this);">
Here im trying to login and keep the page at the current state if the login details are wrong. Here again the form closes / becomes invisible and the page reloads.
<div class="user-modal-container">
<ul class="switcher">
<li><a >Sign in</a></li>
<li><a >New account</a></li>
</ul>
<div id="login">
<form class="form" target="_self" method="post" action="">
<?php include('errors.php'); ?>
<p class="fieldset">
<label class="image-replace email" for="signin-user">Username</label>
<input class="full-width has-padding has-border" id="signin-username" type="text" name="username" placeholder="Username">
</p>
<p class="fieldset">
<label class="image-replace password" for="signin-password">Password</label>
<input class="full-width has-padding has-border" id="signin-password" type="password" name="password" placeholder="Password">
<a class="hide-password">Show</a>
<span class="error-message">Wrong password! Try again.</span>
</p>
<p class="fieldset">
<input type="checkbox" id="remember-me" checked>
<label for="remember-me" style="color:#fff">Remember me</label>
</p>
<p class="fieldset">
<input class="full-width" type="submit" value="Login" name="login_user">
</p>
</form>
<p class="form-bottom-message">Forgot your password?</a></p>
</div>