Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

120
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda