I hope Robusto doesn't mind me extending his solution a bit for a solution that will perform better on the modern browsers. Chrome, Safari, IE8 and Firefox all support querySelectorAll, so it seems more appropriate to use that if it's available.
function getPwdInputs()
{
// If querySelectorAll is supported, just use that!
if (document.querySelectorAll)
return document.querySelectorAll("input[type='password']");
// If not, use Robusto's solution
var ary = [];
var inputs = document.getElementsByTagName("input");
for (var i=0; i<inputs.length; i++) {
if (inputs[i].type.toLowerCase() === "password") {
ary.push(inputs[i]);
}
}
return ary;
}
NB. It shouldn't be a problem but it might be worth noting that querySelectorAll will return a collection, whereas the fallback method will return an array. Still not a big deal, they both have the length property and there members are accessed the same way.