-1

I have this form:

<form method="post">
    <input type="tel" name=phone_no required>
    <input type="password" name=password required>
    <button type="submit">Sign In</button>
</form>

How can I automatically submit this form when browser auto-fills these input fields in form ?

ARK4579
  • 663
  • 2
  • 6
  • 16

1 Answers1

0

You can do this using Javascript :

(1) Get html elements with selector :

document.getElementsByName(..)

(2) Check if the elements contains any value.

element.value

(3) In that case, trigger an event which click on the submit button :

button.click();

Ludo
  • 123
  • 1
  • 9
  • that's ok, but how do I fire/trigger this on autofill by browser? – ARK4579 Dec 04 '19 at 16:40
  • using event listener "on change" on inputs ? – sonic Dec 04 '19 at 16:41
  • 1
    but that would fire every time user makes some change. i.e. let's say he/she is typing "ark4579" it would fire every time there is change i.e. when value is "a", "ar", "ark"... and so on. No? – ARK4579 Dec 04 '19 at 16:43
  • The problem to use "on change" is that event will be triggered on every updates. Are you using jQuery ? – Ludo Dec 04 '19 at 16:43
  • Okay, before you can try to use in this function : window.onload = function () { ... } – Ludo Dec 04 '19 at 16:46
  • I think that every browser could do it differently so it will be very hard to detect in my opinion. Here is the answer https://stackoverflow.com/questions/11708092/detecting-browser-autofill Post by DrNio with 11 votes could be it. – sonic Dec 04 '19 at 16:53
  • yeah, i went through this question and ignore answer because it's too old and we have come a long way since 2012. but this might be it. – ARK4579 Dec 04 '19 at 16:58