
Originally Posted by
dukevn
Can you guys suggest me a "safe" alert - similar to 'echo' in php - that I can add amost everywhere in the code and it will at least show some output?
There is the alert:
or:
Code:
alert(some_variable);
both of which can be really useful, but if used carelessly (like in the middle of a loop) can virtually lock up the browser.
I like alert for some things though, just to see if I got somewhere in the code, ex:
Code:
if(typeof whatever == 'string'){
alert(whatever);
other code;
};
I'll just throw it in there to see two things:
1 ) Did the code branch execute?
2 ) If so, what was the value of whatever?
But, as I say, it can lock up the browser if its in a loop, even one that just repeats 100 times can get tiresome, it doesn't have to be endless to be a pain.
So for situations like that, or that I think might be like that, I'll sometimes set up an element to receive the value:
HTML Code:
<input type="text" id="test">
Then in my code that I'm testing:
Code:
if(typeof whatever == 'string'){
document.getElementById('test').value = whatever;
other code;
};
That way, even if my code is in a loop, it won't lock up, and I'll get to see the value(s) of whatever, or if there are none.
Bookmarks