This sounds like a bad case of Security Theater
Security theater is the practice of investing in countermeasures intended to provide the feeling of improved security while doing little or nothing to actually achieve it.
I say this because in all reality...
Given enough time, effort, and computing power security is nothing more than a delay.
Of course it gets worse than that. Javascript is an computer based language, which means it must be run by a machine. That machine can be told to ignore your Javascript.
What this really means though is that you're asking the wrong question. What you're really asking:
How do you keep your forms safe from someone using saved passwords to fill out the form, and then changing the type of the form to read it?
And to this answer it's pretty simple:
Keep your terminal safe and secure. The only way to prevent this kind of attack is to not let an attacker on a system with a saved password in the first place.
Why? Because you have a "spectrum". Let's call it the security spectrum in this simplified example:
At the basis of simple security you have the following:
Security >----------------------------------------------< Ease of Use
In most cases this is what happens:
The more Security you have, the less Ease of Use you have.
The more Ease of Use you have, the less Security you have.
By using a form that has a password in it and leaving it there, you are increasing your Ease of Use and decreasing your Security