Skip to main content
adicionou 123 caracteres ao conteúdo
Fonte Link
Leandro Angelo
  • 9,4mil
  • 3
  • 23
  • 35

Criei uma função em javascript, porem me retorna o seguinte erro:

Cannot read property 'value' of null

Segue um pedaço do código:

HTML

function defineLetrar() {
  var obj;
  for (var i = 0; i <= 10; i++) {
    let obj = document.getElementById(`letra${i}`).value = ''
    console.log(obj)
    //obj = document.getElementById('letra'+i).style.display = 'none';
  }
}
<input type="text" name="" id="letra1" class="input-text" maxlength="1" disabled>
<input type="text" name="" id="letra2" class="input-text" maxlength="1">
<input type="text" name="" id="letra3" class="input-text" maxlength="1">
<input type="text" name="" id="letra4" class="input-text" maxlength="1">
<input type="text" name="" id="letra5" class="input-text" maxlength="1">
<input type="text" name="" id="letra6" class="input-text" maxlength="1">
<input type="text" name="" id="letra7" class="input-text" maxlength="1">
<input type="text" name="" id="letra8" class="input-text" maxlength="1">
<input type="text" name="" id="letra9" class="input-text" maxlength="1">
<input type="text" name="" id="letra10" class="input-text" maxlength="1">
        <input type="text" name="" id="letra2" class="input-text" maxlength="1">
        <input type="text" name="" id="letra3" class="input-text" maxlength="1">
        <input type="text" name="" id="letra4" class="input-text" maxlength="1">
        <input type="text" name="" id="letra5" class="input-text" maxlength="1">
        <input type="text" name="" id="letra6" class="input-text" maxlength="1">
        <input type="text" name="" id="letra7" class="input-text" maxlength="1">
        <input type="text" name="" id="letra8" class="input-text" maxlength="1">
        <input type="text" name="" id="letra9" class="input-text" maxlength="1">
        <input type="text" name="" id="letra10" class="input-text" maxlength="1">

function defineLetrar() {
    var obj;
    for (var i = 0; i <= 10; i++) {
        let obj = document.getElementById(`letra${i}`).value = ''
        console.log(obj)
        //obj = document.getElementById('letra'+i).style.display = 'none';
    }
}```

 

Criei uma função em javascript, porem me retorna o seguinte erro:

Cannot read property 'value' of null

Segue um pedaço do código:

HTML

        <input type="text" name="" id="letra2" class="input-text" maxlength="1">
        <input type="text" name="" id="letra3" class="input-text" maxlength="1">
        <input type="text" name="" id="letra4" class="input-text" maxlength="1">
        <input type="text" name="" id="letra5" class="input-text" maxlength="1">
        <input type="text" name="" id="letra6" class="input-text" maxlength="1">
        <input type="text" name="" id="letra7" class="input-text" maxlength="1">
        <input type="text" name="" id="letra8" class="input-text" maxlength="1">
        <input type="text" name="" id="letra9" class="input-text" maxlength="1">
        <input type="text" name="" id="letra10" class="input-text" maxlength="1">

function defineLetrar() {
    var obj;
    for (var i = 0; i <= 10; i++) {
        let obj = document.getElementById(`letra${i}`).value = ''
        console.log(obj)
        //obj = document.getElementById('letra'+i).style.display = 'none';
    }
}```

Criei uma função em javascript, porem me retorna o seguinte erro:

Cannot read property 'value' of null

Segue um pedaço do código:

function defineLetrar() {
  var obj;
  for (var i = 0; i <= 10; i++) {
    let obj = document.getElementById(`letra${i}`).value = ''
    console.log(obj)
    //obj = document.getElementById('letra'+i).style.display = 'none';
  }
}
<input type="text" name="" id="letra1" class="input-text" maxlength="1" disabled>
<input type="text" name="" id="letra2" class="input-text" maxlength="1">
<input type="text" name="" id="letra3" class="input-text" maxlength="1">
<input type="text" name="" id="letra4" class="input-text" maxlength="1">
<input type="text" name="" id="letra5" class="input-text" maxlength="1">
<input type="text" name="" id="letra6" class="input-text" maxlength="1">
<input type="text" name="" id="letra7" class="input-text" maxlength="1">
<input type="text" name="" id="letra8" class="input-text" maxlength="1">
<input type="text" name="" id="letra9" class="input-text" maxlength="1">
<input type="text" name="" id="letra10" class="input-text" maxlength="1">
 

Fonte Link

Cannot read property 'value' of null

Criei uma função em javascript, porem me retorna o seguinte erro:

Cannot read property 'value' of null

Segue um pedaço do código:

HTML

        <input type="text" name="" id="letra2" class="input-text" maxlength="1">
        <input type="text" name="" id="letra3" class="input-text" maxlength="1">
        <input type="text" name="" id="letra4" class="input-text" maxlength="1">
        <input type="text" name="" id="letra5" class="input-text" maxlength="1">
        <input type="text" name="" id="letra6" class="input-text" maxlength="1">
        <input type="text" name="" id="letra7" class="input-text" maxlength="1">
        <input type="text" name="" id="letra8" class="input-text" maxlength="1">
        <input type="text" name="" id="letra9" class="input-text" maxlength="1">
        <input type="text" name="" id="letra10" class="input-text" maxlength="1">

function defineLetrar() {
    var obj;
    for (var i = 0; i <= 10; i++) {
        let obj = document.getElementById(`letra${i}`).value = ''
        console.log(obj)
        //obj = document.getElementById('letra'+i).style.display = 'none';
    }
}```