Create an Input Password Element - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Password

Introduction

You can create an <input> element with type="password" by using the document.createElement() method:

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<p>Click the button to create a Password Field.</p>

<button onclick="myFunction()">Test</button>

<script>
function myFunction() {//w  ww . j  a v a2 s .c o  m
    var x = document.createElement("INPUT");
    x.setAttribute("type", "password");
    x.setAttribute("value", "pswtext");
    document.body.appendChild(x);
}
</script>

</body>
</html>

Related Tutorials