Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

111
Visualizações
Uncaught typeerror cannot read property of null (reading 'value') in javascript

I get the error "Uncaught typeerror cannot read property of null (reading 'value')" I'm constantly looking for a solution and I don't know what's wrong in the code, Can you help me?

My code

function test(){

for(var i=0; i < 40; i++) {
var name1.value = document.getElementsByClassName('test1')[i];
var address1.value = document.getElementsByClassName('test2')[i];

if( name1.value == "test4"){
address1.value = "test5";
}
else if (name1.value == "test6"){
address1.value = "test7";
}
else if (name1.value == "test8"){
address1.value = "test9";
}
}
}
< div class="form grup test1">
< labe for="power-full.names"> Names full</lable>
< input name="power-full.names" list="power-full.names" type="text"
class="form grup test1" onclick="test"(this)">
<datalist type"text" id="power-full.names">
<option value="test4">
<option value="test6">
<option value="test8">
</datalist>
</div>


< div class="form grup test2">
< labe for="power-full.adress"> Adress full</lable>
< input name="power-full.adress" list="power-full.adress" type="text"
class="form grup test2" onclick="test"(this)">
<datalist type"text" id="power-full.adress">
<option value="test5">
<option value="test7">
<option value="test9">
</datalist>
</div>

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

You have forgotten to add the classes so document.getElementsByClassName('test1')[i] returns None. And javascript cannot read value property of None. To fix -

<option class="test1" value="test4">
about 4 years ago · Juan Pablo Isaza Relatório

0

first: maybe you should use onchange event to bound the input.test1.

second: change the value of input.test2

function test1(ele){
  var address1 = document.getElementById('test2');

  if( ele.value == "test4"){
    address1.value = "test5";
  } else if (ele.value == "test6"){
    address1.value = "test7";
  } else if (ele.value == "test8"){
    address1.value = "test9";
  }
}
<div class="form grup test1">
  <lable for="power-full.names"> Names full</lable>
  <input name="power-full.names" list="power-full.names" type="text"
    class="form grup test1" onchange="test1(this)">
  <datalist type"text" id="power-full.names">
    <option value="test4">
    <option value="test6">
    <option value="test8">
  </datalist>
</div>


<div class="form grup test2">
  <lable for="power-full.adress"> Adress full</lable>
  <input id="test2" name="power-full.adress" list="power-full.adress" type="text"
  class="form grup test2">
  <datalist type"text" id="power-full.adress">
    <option value="test5">
    <option value="test7">
    <option value="test9">
  </datalist>
</div>

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda