Skip to content

Uncaught TypeError: Cannot read property ‘substr’ of undefined

Pardon me for not being clear, but have thia script that is really long. When I have it live, I get this error in Chrome’s Console.

Uncaught TypeError: Cannot read property ‘substr’ of undefined

here is the snippet of code where it is reading from.

var formIddd = $('select[class~="FormField"]').get(numSelec).name.substr($('select[class~="FormField"]').get(numSelec).name.length-3,2);

I looked up substr on google and it appears to be a known property. I also found the classes. I have played with the lengths, but still getting stuck. It used to work until BigCommerce did an update.

Any advice much appreciated, cheers.

Answer

You are not populating your array. The if check is false.

enter image description here

so basically you are doing this

var arrayOfSelectOfCountry = [];
var numSelec = arrayOfSelectOfCountry[-1];  //undefined

which results in the error above.