Jump to content

Pegar o value de um input quando clicar


PlayGames63

Recommended Posts

PlayGames63

Bom estou a fazer um quiz, e no html eu tenho o seguinte código

<input type="image" id="submit" class="grupos" src="imgs/t.png" name="p1" value="1">

só que no js eu não estou a conseguir que quando a pessoa clique na imagem ele consiga pegar o value para no caso saber em que imagem a pessoa clicou alguém sabe como eu posso faze-lo?

Obrigado.

Link to post
Share on other sites

<script>

function processar1 (botao)
  {
  alert( botao.value )
  }

function processar2 (arg)
  {
  alert( arg )
  }

</script>



<body>

<input type="image" id="submit" class="grupos" src="imgs/t.png" name="p1" value="1" onclick="processar1(this)">

<input type="image" id="submit" class="grupos" src="imgs/t.png" name="p1" value="1" onclick="processar2(1)">

</body>

</html>

  • Vote 1
Link to post
Share on other sites
PlayGames63
Em 24/06/2019 às 12:35, Zex disse:


<script>

function processar1 (botao)
  {
  alert( botao.value )
  }

function processar2 (arg)
  {
  alert( arg )
  }

</script>



<body>

<input type="image" id="submit" class="grupos" src="imgs/t.png" name="p1" value="1" onclick="processar1(this)">

<input type="image" id="submit" class="grupos" src="imgs/t.png" name="p1" value="1" onclick="processar2(1)">

</body>

</html>

Muito obrigado!

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...

Important Information

By using this site you accept our Terms of Use and Privacy Policy. We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.