title: JS error, Uncaught TypeError: Cannot read property 'substring' of undefined
body: <p>I am getting this error, <code>Uncaught TypeError: Cannot read property 'substring' of undefined</code> in a credit card terminal form. </p>
  
  <p>The offending line is: <code>$('#exp-month').val(arr[2].substring(2, 4));</code></p>
  
  <p>This is the whole function. </p>
  
  <pre><code>function checkForReaderInput(string) {
  if (string.substring(0,2) == "%B") {
  string = string.replace('%B', '');
  var arr = string.split('^');
  if (arr[0].length == 16) {
  $('#cardnumber').val(arr[0]);
  $('#exp-month').val(arr[2].substring(2, 4));
  $('#exp-year').val('20'+arr[2].substring(0, 2));
  var nameArr = arr[1].split('/');
  $('#cardholdername').val(nameArr[1]+' '+nameArr[0]);
  setMOP(arr[0].substring(0,1));
  }
  cardParsed = true;
  $('#sdkinputid_cardnumber span.errortext').hide();
  return false;
  }
  setMOP(string.substring(0,1));  // for manual CC# entry
  }
  </code></pre>
  
  <p>What this should do is take the reader input from the <code>cardnumber</code> field and seperate it to fill the form. It does get the card number field but the cursor stays there and the form tries to submit. Alone this works. This did not start happening until I tried including it in a bootstrap form. I got rid of all the validation. All thats left is the stripe gateway scripts. </p>
  
  <p>The page is no longer available</p>