jquery keyup function code example

Example 1: check when keyup an input from a specific form jquery

var inputs = $('#formID').find('input[type="text"]');
inputs.keyup(function() {
   console.log($(this));
});

Example 2: jquery to copy two input fields into one with a space between

jQuery(function($) {
  var $firstname = $('input[name="firstname"]');
  var $lastname = $('input[name="lastname"]');
  var $fullname = $('input[name="fullname"]');

  $firstname.add($lastname).keyup(function() {
    $fullname.val($firstname.val() + ' ' + $lastname.val());
  });
});

Example 3: jquery keyup

// Similar to KeyUp but just called on input change (optimal for AJAX calls)
  var input = $('#formID').find('input[type="text"]');
  input.on('input',
    function(){
      console.log (input.val());
    });

Tags:

C Example