I have a form that i am trying to validate. I have a field that i want to make sure is required. I have the following code for the field:
<p>
<label for="lf">Name: </label>
<input class="lf" name="name" type="text"/>
<span id="name_error" class="validate_error">Please enter a valid name!</span>
</p>
I want to be able to first off if they click in the box and don't type anything and then go to a different box, i want the span tag to show and also if they hit submit and didn't type anything.
I have the following jquery code, but it always shows the span tag no matter what.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.9.0/jquery.min.js"></script>
<script>
$(document).ready(function(){
<!--Name can't be blank-->
$('#name').on('input', function() {
var input=$(this);
var is_name=input.val();
if(is_name){
$("#name_error").hide();
}else{
$("#name_error").show();
}
});
});
</script>
<!-- -->is only for commenting html, not js.$('#name').on('input blur', function() {