Adding place holder by jquery doesn't work fine

63 views Asked by At

I have a input field with id 'datepicker'

While validating, if date mentioned is not valid

I am empty the field and adding the placeholder

 if(validationfails)
 {
    $("#datepicker").val(''); 
    $("#datepicker").attr('placeholder',"MM/DD/YYYY")
 }

Now the input field doesn't have anything, but the placeholder is missing.

if I focus the input field and press "backspace"

The place holder "MM/DD/YYYY" appears

1

There are 1 answers

3
rashidkhan On

Try to change your code to this one. Enclose your IDs in quotes.

            if(validationfails)
        {
            $('#datepicker').val('');
            $('#datepicker').attr('placeholder',"MM/DD/YYYY")
        }