javascript - How To Change textbox textmode using checkbox -


how change textbox textmode password if checkbox unchecked, textbox textmode = text if unchecked, set textmode = password using javascript?

i tried code

 function test() {      if ($('#tbpass12').get(0).type = 'text') {          document.getelementbyid('<%= tbpass12.clientid %>').type = 'password';      }      else if ($('#tbpass12').get(0).type = 'password') {          document.getelementbyid('<%= tbpass12.clientid %>').type = 'text';      }          } 

text mode read only in javascript . cannot change type in js. can 1 thing that, create textbox dynamically , setattribute them , replace previous

try this,

$(function(){    var inp = document.getelementbyid("in");    if(inp.type == 'text'){        var newin = document.createelement('input');       newin.setattribute('type', 'password');      newin.setattribute('id', inp.getattribute('id'));      newin.setattribute('name', inp.getattribute('name'));      inp.parentnode.replacechild(newin, inp);      newin.focus();    }  });
<!doctype html>  <html>      <head>      <meta charset="utf-8" />      <title></title>      <link href="style.css" rel="stylesheet" />      <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.0.0/jquery.js" data-semver="3.0.0" data-require="jquery"></script>      <script src="script.js"></script>    </head>      <body>      <input id="in" type="text"/>    </body>    </html>


Comments