How Do I Return The Value Of The Image In Html/javascript

<!DOCTYPE html><html><body><pid="resultado"></p><imgsrc="Imagens/R5.jpg"id="P1"class="P1"value="R5"onclick="pergunta1(this)"style="width:164px;height:164px;"><imgsrc="Imagens/R2.jpg"id="P2"class="P1"value="R2"onclick="pergunta1(this)"style="width:163px;height:163px;"><imgsrc="Imagens/R8.jpg"id="P3"class="P1"value="R8"onclick="pergunta1(this)"style="width:163px;height:163px;"><script>functionpergunta1(element){
var res="";
if (element.getAttribute("value") == "R5"){
res= "N1_5"
}
elseif (element.getAttribute("value") == "R2"){
res="N1_2"
}
else{
res ="N1_8"
}
element.style.display = "none";
document.getElementById("resultado").innerHTML =res;
}
</script></body></html>
Solution 2:
You need to move the P resultado inside the function to show the value selected
functionpergunta1(){
var valor = $(event.target).attr("value");
var resultado;
if (valor == "R5"){
resultado = "N1_5"
}
elseif (valor == "R2"){
resultado = "N1_2"
}
else{
resultado = "N1_8"
}
$('.P1').hide();
$("#resultado").html(resultado);
}
<scriptsrc="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script><pid="resultado"></p><imgsrc="Imagens/R5.jpg"id="P1_Imagen1"class="P1"value="R5"onclick="pergunta1()"style="width:164px;height:164px;"><imgsrc="Imagens/R2.jpg"id="P1_Imagen2"class="P1"value="R2"onclick="pergunta1()"style="width:163px;height:163px;"><imgsrc="Imagens/R8.jpg"id="P1_Imagen3"class="P1"value="R8"onclick="pergunta1()"style="width:163px;height:163px;"></p>
Post a Comment for "How Do I Return The Value Of The Image In Html/javascript"