Duplicate error message printing if user click button multiple times
i am trying to validate user form input field using jQuery. it is validating correctly but error message showing multiple times if i clicked submit button multiple times.
it has to clear previous message before printing new one.
My JQuery Code is:
- $(document).ready(function(){
- $('#createUserForm').unbind('submit').bind('submit', function(){
- var username = $("#userName").val();
- if(username == ""){
- $("#userName").after('<p class="text-danger">Username required ?</p>');
- $("#Username").closest('.form-group').addClass('has-error');
- }else{
- $("#userName").find('.text-danger').remove();
- $("#userName").closest('.form-group').addClass('has-success');
- }
- return false;
- });
- });
output is :