0

I have a phone input on a form. Im using masked input and i had to create a span simulating a value for when user clicks the input it removes the span, but if the user doesnt fill all the mask, on blur, it doenst show the false value (span im using).

Im using span coz i had the same issue using value..

$('#telefone').on({
            focus: function(){
                $('#contato span.value_telefone').hide();
                $('#contato #telefone').mask('(99) 9999-9999');
            },
            blur: function(){
                if($('#contato #telefone').val()=='' || $('#contato #telefone').val()=='(__) ____-____'){
                    $('#contato span.value_telefone').show();
                }
            }
        });
        $('#contato span.value_telefone').click(function(){
            $(this).hide();
            $('#contato #telefone').mask('(99) 9999-9999');
            $('#contato #telefone').focus();
        });
Ramon Vasconcelos
  • 947
  • 3
  • 14
  • 31

1 Answers1

0

it's not the exact same functionality, but much much more easier would be using html5 placeholder attribute:

<input name="tel" placeholder="(99) 9999-9999"/>
monxas
  • 2,475
  • 2
  • 20
  • 36