Jump to content
Sign in to follow this  
Mudsaf

Chrome Console gives errors, but code works

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 :)

Share this post


Link to post
Share on other sites

code/link would be awesome.

  • Like 1

Share this post


Link to post
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++){

Share this post


Link to post
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

Share this post


Link to post
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....

Share this post


Link to post
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.

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...