Archive for August, 2007

ASP VBScript function to generate random password

August 17th, 2007 by Denis Golovtsov

Sometime I have to work with ASP projects. I don’t like ASP. At first because it’s old technology which almost doesn’t use in new projects now and this experience won’t very helpful. Any way I’d like to present here one simple function that might help someone.


‘       Generate random password

‘       @author Denis Golovtsov, http://goldenman.spb.ru/
       @param length integer - Tne length of generated password.
‘       @output string - Generated password.

Public Function NewPassword(length)

Dim range,password

range = “0123456789abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ”
password = “”

Randomize

While length > 0
password = password & Mid(range, 1 + Int(Len(range) * Rnd), 1)
length = length - 1
Wend

NewPassword = password

End Function

I’m sure all are clear there and it doesn’t require additional comments.

IE DOM limitation for <input type=checkbox> element

August 7th, 2007 by Denis Golovtsov

I has found a strange limitation for IE (tested in IE7) when we make <input type=checkbox> object dinamically trough DOM manipulation methods.

var h = document.createElement(‘input’);
h.setAttribute(‘name’,‘flag’);
h.setAttribute(‘type’,‘checkbox’);
h.setAttribute(‘value’,1);
div.appendChild(h);

So try to set in the same way ‘checked’ value like:

h.setAttribute(‘checked’,true);

Don’t give proper effect. The same won’t give proper effect other variants:

h.setAttribute(‘checked’,‘checked’);
h.checked = true;
h.checked = ‘checked’;
h[checked] = true;
h[checked] = ‘checked’;
h[‘checked’] = true;
h[‘checked’] = ‘checked’;

Of course all of them do the same and no reason check all of them, but when don’t know exactly where is problem begin check all possible variants ;)

Any way I found in Internet solution that gives right effect:

div.appendChild(h);
div.lastChild.checked = true;

Furthermore, trough div.lastChild will work correct all variants that presented above.

Link to page where I found solution.

I sure ‘checkbox’ isn’t one of property that in IE can be defined on “live” object only, somethings like this I had when was trying to set ‘onclick’ attribute for dynamic element, but I solved it with help addEventListener and attachEvent handlers, they work fine in “off-line” elements.