Skip to content Skip to sidebar Skip to footer

How Do I Return The Value Of The Image In HTML/Javascript

Copy

Solution 2:

You need to move the P resultado inside the function to show the value selected

function pergunta1(){
    var valor = $(event.target).attr("value");
    var resultado;

        if (valor == "R5"){
            resultado = "N1_5"
        }
        else if (valor == "R2"){
            resultado = "N1_2"
        }
        else{
            resultado = "N1_8"
        }
        $('.P1').hide();  
        $("#resultado").html(resultado);
    }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<p id="resultado"></p>
    <img src="Imagens/R5.jpg" id="P1_Imagen1" class="P1" value="R5" onclick="pergunta1()" style="width:164px;height:164px;">
    <img src="Imagens/R2.jpg" id="P1_Imagen2" class="P1" value="R2" onclick="pergunta1()" style="width:163px;height:163px;">
    <img src="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"