Mudsaf Posted March 11, 2013 Share Posted March 11, 2013 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 More sharing options...
thescientist Posted March 11, 2013 Share Posted March 11, 2013 code/link would be awesome. 1 Link to comment Share on other sites More sharing options...
Mudsaf Posted March 11, 2013 Author Share Posted March 11, 2013 Oh lol i forgot to link site, my bad. http://mudsaf.info/register.php Link to comment Share on other sites More sharing options...
thescientist Posted March 11, 2013 Share Posted March 11, 2013 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 More sharing options...
Mudsaf Posted March 11, 2013 Author Share Posted March 11, 2013 (edited) 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 March 11, 2013 by Mudsaf Link to comment Share on other sites More sharing options...
thescientist Posted March 11, 2013 Share Posted March 11, 2013 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 More sharing options...
Mudsaf Posted March 11, 2013 Author Share Posted March 11, 2013 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now