Javascript DOM HTML Input Password Object create

Introduction

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

var x = document.createElement("INPUT"); x.setAttribute("type", "password");

Click the button to create a Password Field.

View in separate window

<!DOCTYPE html>
<html>
<body>
<button onclick="myFunction()">Test</button>

<script>
function myFunction() {/* www.  j av  a2 s. c  om*/
  var x = document.createElement("INPUT");
  x.setAttribute("type", "password");
  x.setAttribute("value", "pswtext");
  document.body.appendChild(x);
}
</script>

</body>
</html>



PreviousNext

Related