Cannot set input field with type password and autocomplete using javascript

506 views Asked by At

I am working on an automatic login feature by filling in the username and password for a web application using javascript. The password field has the autocomplete feature activated. It's HTML is as below -

<input name="autofill_password" type="password" style="display:none">
<input name="user_password" type="text" onfocus="this.setAttribute('type', 'password')" id="user_password" maxlength="256" class="loginField" autocomplete="new-password">

I am unable to set the value using javascript or jquery for the "user_password" field. I have tried the following with no luck -

$('#user_password').val("g");
$('#user_password').attr('value', 'new value');
document.getElementById('user_password').value = 'Welcome!1';
document.getElementById('user_password').setAttribute('type', 'text');

What is preventing the setting of the value and what else can I try?

1

There are 1 answers

0
user9057272 On

So, this is for all the other simpletons like me, the issue was, that there was a label with the same id as password field.