I want to create a validation form which is where the border input is red then set required or cant submit.iam using jquery ajax.
i am using ajax call to do some validation on the server side and after receiving the response i want to decide if i want to submit the form or not.
i want call some validation using jquery on 'keyup' and then if the input got validation error set input required so the users cant submit
<input type="text" class="form-control" placeholder="Username" name="username" id="username" required/>
here is my code ajax:
<script type="text/javascript">
$(document).ready(function(){
$('#username').on('keyup',function(){
var selectData = $(this).val();
var url ="Author/Fvalidation";
$.ajax({
type:"POST",
url:"<?php echo base_url() ?>"+url,
data:{'selectData':selectData},
success:function(data){
if (data === 'error') {
$('#username').css("border","2px solid red");
$('#username').removeAttr('value');
$('#username').attr("required","true");
}else {
$('#username').css("border","2px solid green");
}
}
});
});
});
</script>