Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Clear password field

<input name="e_password" id="e_password" type="password" autocomplete="off" />

The above is a password field which for some reason, is automatically filled only in Mozilla (not in Chrome and IE11). Obviously it keeps the value field from previous trials. I tried so much to clear this field. The only way I can manage it, is through the following:

$(document).ready(function(){      
  $('input:text').val(''); 
});

Unfortunately, the above resets all the other text fields inside the form which is undesirable. Also,

$(document).ready(function(){
    $('input:password').val('');
}); 

does not work! Moreover, I tried this:

<div class="abc">   
   <input name="e_password" id="e_password" type="password" autocomplete="off" />
</div>

$(document).ready(function(){
    $('.abc input:text').val('');    
});

Nor, this works... Of course, I tried the obvious:

$('#e_password').val(''); 

which also did not work. I repeat that the problem exists only in Mozilla. What else may I do?

Thank you

like image 539
Unknown developer Avatar asked Mar 16 '23 07:03

Unknown developer


2 Answers

document.getElementById("e_password").value = "";

or

$('input[type="password"]#e_password').val('');
like image 70
Darshan Patel Avatar answered Mar 29 '23 04:03

Darshan Patel


I found it!!

setTimeout(function(){ $('#e_password').val('');}, 50);

Hopefully, the above works. However, I cannot give a satisfactory explanation why this small delay solves the problem...Most probably, it is a Mozilla bug.

like image 40
Unknown developer Avatar answered Mar 29 '23 06:03

Unknown developer