'Uncaught TypeError: Cannot read property 'which' of undefined in JavaScript

What I am trying to this is on click of button it shows my textfield and the textfield is linked with a file Payment.php which has the querying code. So when an ID from the table in database is entered then on press of enter button it should display output in div test. My first textbox works fine displays the putput aswell. But the Second Textbox is giving error.

Uncaught TypeError: Cannot read property 'which' of undefined

$(document).ready(function() {
  //Second TextBox  
  $('#UserID').hide();
  $('#Payment').click(function() {
    alert("Touch Card For Payment");
    $('#UserID').show().focus();
  });
  $('#UserID').keypress(function(event) {
    var key = event.which;
    if (key == 13) {
      var UserID = $('input#UserID').val().trim(); // retreiving the value from the item
      if (UserID != '') { //send this to php file but if its empty or spaces(trim) are there dont send it//
        $.post('ajax/Payment.php', {
          user: item
        }, function(data) { //using post method sending to the father(name.php), sending the data through the file item
          $('div#test').append("" + data + "</br>"); // grabing the data and displaying it
        });
      };
      $('#UserID').val('');
    }
  });

  //First textBOX   
  var sum = 0;
  $('#item').keypress(function(event) {
    var key = event.which;
    if (key == 13) { // the enter key code
      var item = $('input#item').val().trim(); // retreiving the value from the item
      if (item != '') { //send this to php file but if its empty or spaces(trim) are there dont send it//
        $.post('ajax/name.php', {
          id: item
        }, function(data) { //using post method sending to the father(name.php), sending the data through the file item
          $('div#item-data').append("" + data + "</br>"); // grabing the data and displaying it
          $('.price').each(function() {
            sum += parseInt($(this).html());
          });
          $('#total-amount').html(sum);
          sum = 0;
        });
      }
      $('#item').val('');
    }
  });
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source