Dropsen Dropsen - 4 months ago 10
jQuery Question

Printing message after typing in form input

everyone. I really want to know how to do effect similar to this:


https://www.dosomething.org/user/register


I mean, I want to change for example: 'First Name' to 'Hello, (and typed text in the input after changing input type. If you know how to do similar effect for example in jQuery or other plugins tell me, please! I know how to print typed text in the input, but it isn't what I want to do, because I want to show full text: 'Hello, (typed msg) after using tab or changing input field.
I appreciate every kind of help.

Answer

HTML

<div class="form-group">
    <label id="label-name" for="name">First Name</label>
    <input class="form-control" type="text" id="name" placeholder="Enter your name" />
</div>

jQuery

$('#name').on('change', function() {
    var val = $('#name').val();
  if(val)
      $('#label-name').html('Hi ' + val);   
  else
  {
      $('#label-name').html('First Name');
  }
})

Fiddle: https://jsfiddle.net/on142Lvp/