Get radio button value via jQuery and call a code

Asked

Viewed 64 times

0

Good morning, I would like to receive a help, I am beginner in the area of programming. I need to know how to make whatever is selected the radio it calls a certain code.

<form method="POST" action="questoes.php">
    <label>Tipo da questão:</label><br>
    <input type="radio" name="tipo" value="dissertativa"> Dissertativa <br>
    <input type="radio" name="tipo" value="objetiva"> Objetiva <br><br>

    <input type="button" name="pergunta" id="pergunta" value="pergunta">
</form>
  • And what code would that be? a function? does that code run on an HTML page? Have you tested oninput="minhaFuncao()"?

  • it’s not clear, you want to make a if to execute a code according to the radio value?

1 answer

0


Your question is not very clear, but if when you say call another code is redirect the page you can use href. HTML:

    <form method="POST" action="questoes.php">
 <label>Tipo da questão:</label><br>
<input id="dissertativa" type="radio" name="tipo" value="dissertativa"> Dissertativa <br>
<input id="objetiva" type="radio" name="tipo" value="objetiva"> Objetiva <br><br>

<input type="button" name="pergunta" id="pergunta" value="pergunta">
        </form>

jQuery

    $(document).ready(function(){ //eu acrescentei o id nos inputs
            $("#dissertativa").click(function(){
              window.location.href = "http://answall.com"
            })
        });
    $(document).ready(function(){ 
            $("#objetiva").click(function(){
              window.location.href = "http://answall.com"
            })
        });
    $(document).ready(function(){ 
            $("#pergunta").click(function(){
              window.location.href = "http://answall.com"
            })
        }); 

Browser other questions tagged

You are not signed in. Login or sign up in order to post.