Learning jQuery...Part Two

Learning jQuery...Part Two

Earlier today, I had someone show me how to convert a javascript method to full jQuery syntax. Now, I am wondering about splitting the function they helped me with in two. This way, I can use the number checking part for a lot of areas in my application and still call on the math portion of the code when needed. Can someone show me the best way to do that? Attached is the complete code to verify a number and then do the math. 

  1. $(function () {
  2. $('.numberOfStudentsParticipating, .numberOfStudentsMetOutcome').keydown(function (e) {
  3. var code = e.keyCode;
  4. if (code < 16) return;
  5. if ((code < 48 || code > 57) && (code < 96  || code > 105)) e.preventDefault()
  6. }).keyup(function () {
  7. var percentage = '',
  8. firstNumber = $('.numberOfStudentsParticipating').val(),
  9. secondNumber = $('.numberOfStudentsMetOutcome').val();
  10. if (firstNumber.length && secondNumber.length)
  11. percentage = ((secondNumber / firstNumber).toFixed(4)) * 100 + "%";
  12. $('.percentageOfStudents').val(percentage);
  13. })
  14. })