Jump to content

Chrome Console gives errors, but code works


Mudsaf

Recommended Posts

On my register page when i enter character to username field google chrome console will give me this error: Uncaught TypeError: Cannot read property 'name' of undefined Fix would be awesome :)

Link to comment
Share on other sites

this for loop doesn't look right,

for (var i=0; names_check.length > 1; i++) {

i don't think you're actually setting an ending condition and instead going out of bounds on the array. maybe something like this?

for(var i = 0,  l = names_check.length; i < l; i++){

Link to comment
Share on other sites

umm the loop is working fine, only thing is wrong that it gives error in console that actually doesn't effect the code. So the code works but id like it to be error-free. Atm its giving error on this line

if (names_check[i].name == $("#username_reg").val()) {

names_check[i].name // .name part which comes from  var names_check = [{"name" :"example"}];

Edited by Mudsaf
Link to comment
Share on other sites

If it can't find the value of name because check_names is undefined, doesn't that imply that loop is in fact, not working correctly? It would interesting to see what exactly is in names_check and what the value of i is at each iteration. I can't imagine it's a good thing to start a loop but not end it, while also referencing an array at its indexes. You can just log and confirm instead of guessing I suppose....

Link to comment
Share on other sites

Yea you was right there was 1 typo in for loop.

for (var i=0; names_check.length > 1; i++) {

Had to be

for (var i=0; names_check.length > i; i++) {

Thx for help.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...