JavaScript - Uncaught TypeError: Cannot read property 'dataset' of null

 
Vista:

Uncaught TypeError: Cannot read property 'dataset' of null

Publicado por Jordi (10 intervenciones) el 23/03/2016 18:56:16
Hola! tengo un script con el que voto comentarios pero a la hora de votar no hace nada... sale un error en la consola del navegador:

Uncaught TypeError: Cannot read property 'dataset' of null
index.php?pe=opiniones-productos&opinion=3-&categoria=informatica_datos-&id-categoria=3-:504 Uncaught TypeError: Cannot read property 'dataset' of nullvotar_positivo @ index.php?pe=opiniones-productos&opinion=3-&categoria=informatica_datos-&id-categoria=3-:504onclick @ index.php?pe=opiniones-productos&opinion=3-&categoria=informatica_datos-&id-categoria=3-:439

Alguien podría ayudarme plis?

Aquí el código:

1
2
3
4
5
<img style="float:left;" src="../images/me-gusta.png" id="votopositivo<? echo $row['id']; ?>" onclick="javascript:votar_positivo();" data-id="<? echo $row['id']; ?>" data-voto="positivo">
 <span style="float:left;font-size:12px;color:#908E8E;" id="votarpositivo<? echo $row['id']; ?>">&nbsp;<? echo $row['me_gusta']; ?></span>
 
<img style="float:left;" src="../images/no-me-gusta.png" id="votonegativo<? echo $row['id']; ?>" onclick="javascript:votar_negativo();" data-id="<? echo $row['id']; ?>" data-voto="negativo">
<span style="float:left;font-size:12px;color:#908E8E;" id="votarnegativo<? echo $row['id']; ?>">&nbsp;<? echo $row['no_me_gusta']; ?></span>

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
<script language="javascript">
function votar_positivo(){
    var variable_post="<? echo $categoria_opiniones; ?>";
    var id = document.getElementById('votopositivo'+id).dataset.id;
    var voto = document.getElementById('votopositivo'+id).dataset.voto;
 
    $.post("../includes/votar.php", { variable: variable_post, 'id':id, 'voto':voto }, function(data){
    $("#votarpositivo"+id).html(data);
    });
}
function votar_negativo(){
    var variable_post="<? echo $categoria_opiniones; ?>";
    var id = document.getElementById('votonegativo'+id).dataset.id;
    var voto = document.getElementById('votonegativo'+id).dataset.voto;
 
    $.post("../includes/votar.php", { variable: variable_post, 'id':id, 'voto':voto }, function(data){
    $("#votarnegativo"+id).html(data);
    });
}
</script>

la linea donde da el error es esta:

1
var id = document.getElementById('votopositivo'+id).dataset.id;

Gracias
Valora esta pregunta
Me gusta: Está pregunta es útil y esta claraNo me gusta: Está pregunta no esta clara o no es útil
0
Responder
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Uncaught TypeError: Cannot read property 'dataset' of null

Publicado por xve (2100 intervenciones) el 24/03/2016 15:19:07
Hola Jordi, viendo el código, no se que es dataset... exactamente que es??
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar
Imágen de perfil de xve
Val: 3.162
Oro
Ha mantenido su posición en JavaScript (en relación al último mes)
Gráfica de JavaScript

Uncaught TypeError: Cannot read property 'dataset' of null

Publicado por xve (2100 intervenciones) el 25/03/2016 08:27:07
Hola Jordi, gracias por mostrarlo, lo desconocia... nos puedes mostrar el código html que contiene el id votopositivo
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar

Uncaught TypeError: Cannot read property 'dataset' of null

Publicado por Jordi (10 intervenciones) el 31/03/2016 14:32:51
Perdona, he estado ausente estos días, el cogido html es este:

1
<img style="float:left;" src="../images/me-gusta.png" id="votopositivo<? echo $row['id']; ?>" onclick="javascript:votar_positivo();" data-id="<? echo $row['id']; ?>" data-voto="positivo">
Valora esta respuesta
Me gusta: Está respuesta es útil y esta claraNo me gusta: Está respuesta no esta clara o no es útil
0
Comentar