-4

I want to make a auto login bot. now I only found the GetElementsbyID tutorials, but when i look at the code there is no ID it looks like this:

<input size="12" name="username" value="Username" onfocus="clickClear(this, 'Username')" onblur="clickRecall(this, 'Username')" type="text">

my question is: How do fill in my text in these textboxes?

Plantje
  • 18
  • 2
  • 8

2 Answers2

2

use querySelector() to access the element and use value to change the value.

 var input = document.querySelector('input[name="username"]');
 input.value= 'whatever;
Ramanlfc
  • 8,283
  • 1
  • 18
  • 24
1

If there is no Id, you will have to access the element by another property.

In your specific example, you could probably do with getElementsByName('username').

Note that unlike GetElementById, this is elements, plural. You will receive a list of matches.

If you know that you are always matching exactly one element with this query, you can for instance write

document.getElementsByName('username')[0].value = 'test';
<input size="12" name="username" value="Username" onfocus="clickClear(this, 'Username')" onblur="clickRecall(this, 'Username')" type="text">
David Hedlund
  • 128,221
  • 31
  • 203
  • 222