Darkranger85 Posted March 10, 2012 Share Posted March 10, 2012 Hey guys, I'm trying to add a little bit of JavaScript to my toolbox of knowledge and I'm finding that, for me, it's a lot harder to pick up than PHP was. The main reason for this being that when there is an error in my code, it doesn't seem to tell me anything about the error. It just "doesn't work." This is extremely frustrating because it makes my progress very very slow because I have to sit there and search my entire code trying to find where the error is and considering I just started learning JS, that can take a long time cause I'm not as familiar with the syntax. Is there some kind of "error reporting" that I have to turn on or something? Thanks! Quote Link to comment Share on other sites More sharing options...
ginerjm Posted March 10, 2012 Share Posted March 10, 2012 I also am a fairly new JS developer/user and know what you mean. For me, doing my testing in IE, I find that the little yellow icon in the lower left corner provides a handy pointer to the offending line of code and usually clues me into which line needs my attention. Double click it and see what it says next time you see it appear. Also if you are testing your work on an iphone or ipad, turn on the debug console in Safari. Similar info is provided there. Quote Link to comment Share on other sites More sharing options...
Darkranger85 Posted March 10, 2012 Author Share Posted March 10, 2012 Thanks, that's good to know! I guess a lot of my problem comes from not knowing the syntax all that well. But, thinking back, I guess it was the same when I started learning PHP. Getting errors in just about every single test run, normally ending up being something stupid like missing a semi colon and such lol. But I just can't figure this out. function RegValidate(){ var error = new Array(); //Setup error array and validation variables// var _user = document.forms['register'].username.value; var _pass = document.forms['register'].password.value; var _pass2 = document.forms['register'].password2.value; var _email = document.forms['register'].email.value; var _email2 = document.forms['register'].email2.value; if(empty(_user)){ error[] = 'Please enter a username.'; alert('I hate JavaScript!'); } } The code stopped working after I tried to add string to the error array. I looked up arrays and how to insert information into them and it seems right to me. Quote Link to comment Share on other sites More sharing options...
trq Posted March 10, 2012 Share Posted March 10, 2012 IE sucks for developing JavaScript as it's developer tools leave a lot to be desired. Firefox has an extension called firebug which is awesome, and chrome has a built in console. Both of these tools help a great deal. Quote Link to comment Share on other sites More sharing options...
nogray Posted March 11, 2012 Share Posted March 11, 2012 Javascript doesn't have a method called empty. You would have to compare the value to empty string (e.g. val == ''). To add content to an array, you would use the push method (e.g. my_arr.push('my value'); ) Quote Link to comment Share on other sites More sharing options...
Darkranger85 Posted March 11, 2012 Author Share Posted March 11, 2012 Javascript doesn't have a method called empty. You would have to compare the value to empty string (e.g. val == ''). To add content to an array, you would use the push method (e.g. my_arr.push('my value'); ) Sorry, I should have also included this: function empty(obj) { if (typeof obj == 'undefined' || obj === null || obj === '') return true; if (typeof obj == 'number' && isNaN(obj)) return true; if (obj instanceof Date && isNaN(Number(obj))) return true; return false; } my own empty function! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.