Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Button on-click is only working once [closed]

I can't figure out why the OnClick event won't happen again in my code; see the jsfiddle here: http://jsfiddle.net/btcAx/2/

html:

<input id="LoginID" readonly="readonly" type="password" value="UserName"/>
<br/>
<input id="LoginPW" readonly="readonly" type="password" value="Password"/>
<br/>
<input onclick="change()" type="button" value=" Show/Hide Text " id="ChangeButton"/>

JS:

function change() {
  var inp1 = document.querySelector('#LoginID');
  var inp2 = document.querySelector('#LoginPW');

  if (inp1.type = "password") {
      inp1.type = "text";
      inp2.type = "text";
  }
  else {
      inp1.type = "password";
      inp2.type = "password";
  }
}

It will change from password to text type, but then it won't change back...

like image 346
GothamHunter Avatar asked Jan 20 '26 02:01

GothamHunter


2 Answers

Try

if (inp1.type == "password") {

instead of

if (inp1.type = "password") {
like image 73
Martin Avatar answered Jan 21 '26 17:01

Martin


if (inp1.type = "password") {

should be

if (inp1.type == "password") {
like image 38
Lignum Avatar answered Jan 21 '26 16:01

Lignum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!