I have the following code in a form, it belongs to a column of a table with data collected from a MySQL database.
echo "<td width=\"08%\" id=\"estado".$row['ID_OBLIGATORIO']."\">" ?>
<!-- Columna ESTADO del usuario. -->
<center>
<?php
$estado = 1;
echo "<a href='#' onclick='return cambiar_estado(".$row['ID_OBLIGATORIO'].");'\">";
echo "<img src=\"/imagenes/".$row['estado'].".gif\">";
echo "</a>";
?>
</center>
<?php
echo "</td>";
Now I have the following function, in which clicking on each ID element of the state column of the table, I would put an image x.gif, or put a text "We have clicked on this image" as a series to test.
<script language="Javascript">
function cambiar_estado() {
var img = "";
var pregunta = confirm("¿Qué deseas elegir?");
if (pregunta == true) {
mg = "<center><img src='imagenes/0.gif'/></center>";
} else {
tmg = "<center><img src='imagenes/2.gif'/></center>";
}
document.getElementById("estado" +id).innerHTML = img;
}
</script>
What I want is that if all the rows start (all users) have the state = 1, I let me click to ask: Do you want to change the state = 0 or state = 2? And automatically call the image. I've already done that, but ... I edit the question: I have read that you can not change the alert or confirm () options - Cancel or Accept -, only if plugins or jQuery are used. Is it like that?
Why does not the function work with the following code? Of course, it does not give me failures in the console ... how weird you should not take the "id".
function cambiar_estado(id) {
var imagen = "";
//alert("El ID elegido es: "+id);
var pregunta = confirm("¿Qué deseas elegir?");
if (id == '1') {
if (pregunta == true) {
imagen = "<center><img src=\"/imagenes/0.gif\"></center>";
} else {
imagen = "<center><img src=\"/imagenes/2.gif\"></center>";
} else if (id == '0') {
if (pregunta == true) {
imagen = "<center><img src=\"/imagenes/1.gif\"></center>";
} else {
imagen = "<center><img src=\"/imagenes/2.gif\"></center>";
} else {
imagen = "<center><img src=\"/imagenes/0.gif\"></center>";
} else {
imagen = "<center><img src=\"/imagenes/1.gif\"></center>";
}
document.getElementById("estado" +id).innerHTML = imagen;
}