I've made quite a few changes to my bookmarklets experiment. :)

Originally Posted by
xDev
Cool bookmark by the way. Could be very useful in debugging.
I get an error in IE6 upon clicking evaluate:
Error: 'this.form.xDebugTA.value' is null or not an object
I think I've fixed that now. At least, it works for me with IE6/Win2K.

Originally Posted by
xDev
Not sure, but I thought you had to have uppercase arguments for ie to create, append elements or do anything with the DOM:
document.createElement('FORM');
Thanks, I made that change.

Originally Posted by
xDev
I have a convention when making them. I usually define a variable with an underscore before it, i.e. _i, _j or whatever. The reason is that if you go on someone's page and try and use the bookmark, there may be conflicts with the variables if there are any scripts on their page - vars like str, msg, i, a, b etc. and such could cause problems cause everyone uses the same name.
Good advice. I had enclosed my variable declarations with curly braces, like this:
Code:
{
var f = document.createElement('FORM');
f.onsubmit = 'return false';
var t = document.createElement('TEXTAREA');
t.id='xDebugTA';
t.name='xDebugTA';
t.rows='20';
t.cols='60';
var b = document.createElement('INPUT');
b.type = 'button';
b.value = 'Evaluate';
b.onclick = function() {eval(this.form.xDebugTA.value);};
f.appendChild(t);
f.appendChild(b);
document.body.appendChild(f);
}
I was thinking that the braces defined a new 'local' scope and the variables would not be global. Of course, I was confusing javascript with C :) so now I just made a function out of it to minimize global variable conflicts. Still needs testing of course ;)
Code:
function xEvalTA_load()
{
var f = document.createElement('FORM');
f.onsubmit = 'return false';
var t = document.createElement('TEXTAREA');
t.id='xDebugTA';
t.name='xDebugTA';
t.rows='20';
t.cols='60';
var b = document.createElement('INPUT');
b.type = 'button';
b.value = 'Evaluate';
b.onclick = function() {eval(this.form.xDebugTA.value);};
f.appendChild(t);
f.appendChild(b);
document.body.appendChild(f);
}
xEvalTA_load();

Originally Posted by
xDev
You might have known this before, IE6 only allows you to have a maximum of 480 characters. Mozilla you can have alot more, can't remember exactly.
I separated my functions into different bookmarklets. Thanks for the tip.
Thanks to everyone for their contributions to this thread. I think it turned out to be very informative (and fun) for all of us :)
Bookmarks