Change input field type - Javascript DOM HTML Element

Javascript examples for DOM HTML Element:Input Text

Description

Change input field type

Demo Code

ResultView the demo in separate window

<html>
   <head> 
      <meta name="viewport" content="width=device-width, initial-scale=1"> 
      <script type="text/javascript">
function show(x, y) {/*from ww w .  java2s  .  com*/
    if (document.getElementById(y).checked) {
        document.getElementById(x).type = 'text';
    } else {
        document.getElementById(x).type = 'hidden';
    }
}

      </script> 
   </head> 
   <body> 
      <input id="txt" type="text" value="Hello"> 
      <input id="chk" type="checkbox" checked onclick="show('txt', 'chk')">  
   </body>
</html>

Related Tutorials