JpaytonWPD JpaytonWPD - 9 months ago 42
Javascript Question

JS error, Uncaught TypeError: Cannot read property 'substring' of undefined

I am getting this error,

Uncaught TypeError: Cannot read property 'substring' of undefined
in a credit card terminal form.

The offending line is:
$('#exp-month').val(arr[2].substring(2, 4));

This is the whole function.

function checkForReaderInput(string) {
if (string.substring(0,2) == "%B") {
string = string.replace('%B', '');
var arr = string.split('^');
if (arr[0].length == 16) {
$('#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]);
cardParsed = true;
$('#sdkinputid_cardnumber span.errortext').hide();
return false;
setMOP(string.substring(0,1)); // for manual CC# entry

What this should do is take the reader input from the
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.

The page is no longer available

Answer Source

It turns out when I moved to the new form I forgot an ID that surrounds the form. Once I replace it the errors went away and it auto completes.