2

I´m trying to automate the filling of some information in a webpage with javascript.

All the fields have IDs, for example:

<div id="cc-container" class="field has-float-label">
     <input placeholder="ccnumber" id="credit_card_number" maxlength="16" name="credit_card[ovv]" size="16" type="tel" value="">
</div>

And then I just insert the info with:

document.getElementById("credit_card_number").focus();
document.getElementById("credit_card_number").value = variable_ccnumber;

But the last one doesn´t have an ID:

<div id="cvv-container" class="visa has-float-label">
     <input placeholder="cvv" maxlength="4" name="credit_card[meknk]" size="4" type="tel" value="">
</div>

How can I insert what I want in this case?

Thanks.

PD: I'm only starting to code so please don´t assume I will understand everything you throw at me

Jesus Chueca
  • 33
  • 1
  • 5

1 Answers1

2

You can try with Document.querySelector() which allows any valid CSS as selector with name attribute:

document.querySelector('[name="credit_card[meknk]"]').value = 'variable_ccnumber';
<div id="cvv-container" class="visa has-float-label">
  <input placeholder="cvv" maxlength="4" name="credit_card[meknk]" size="4" type="tel" value="">
</div>
Mamun
  • 66,969
  • 9
  • 47
  • 59