Saturday, 31 August 2013

Back to top not focusing on required field

Back to top not focusing on required field

I have a submit button in a form and have implemented jquery back to top
on it. It works fine however when I press the submit button it just goes
to top ignoring the required field attribute for one of my fields. If I
remove the backtotop id from the submit button I can see the required
field error. It just doesn't submit the form if I add backtotop id on the
submit button. What am I missing?
<form action="" method="post">
<input type="text" name="fname" required>
<input type="submit" id="backToTop" class="button" value="Register">
</form>
jQuery(document).ready(function($){
$(window).scroll(function(){
if ($(this).scrollTop() > 50) {
$('#backToTop').fadeIn('slow');
} else {
$('#backToTop').fadeOut('slow');
}
});
$('#backToTop').click(function(){
$("html, body").animate({ scrollTop: 0 }, 100);
return false;
});
});

No comments:

Post a Comment