Below is my code. What I want to do is add validation so when the user clicks off an input field the validation message "name required" shows up. However at the minute it is just below the input field and is there all the time. Thank you
$(document).ready(function(){
if($('#firstname').val() == ''){
$('.errorMsg').show();
} else{
$('.errorMsg').hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<label for="firstname">First Name</label>
<input type="text" name="firstname" id="firstname" placeholder="First name" maxlength="15" <span class="errorMsg">Name required </span>
</input>
maxlength-attribute. People tend to have more interesting names than most webdevelopers can imaginemaxlengthis not a bad thing per se. No matter how much you accept in the database, there is a limit somewhere.