How do I trigger a function when I click on an input of the radio type?

2

I have 2 inputs of type radio . In them, I'm trying to trigger my JS method. However, clicking on the radio button , nothing is done. You do not even want to get to the JS function:

function onView1(){
    alert("oi");
    var x = document.getElementsByName("user_1");
    if(x.value== 1){
        location.href = "option_user.html";
    }else {
        alert("nao deu");
    }
}
<tr>
    <td>
        <div align="center">    
            <br><br>
            <img src="images/Untitled-1.jpg"><br><br>
            <input type="radio" name="user_1" value="1" id="1" onkeyup="onView1()"/>
        </div>
    </td>
</tr>
    
asked by anonymous 05.09.2016 / 23:07

1 answer

3

If you want something to happen when you click input , use the onclick instead of onkeyup :

function mudaDePagina(){
  location.href = 'http://pt.stackoverflow.com';
}
<input type='radio' onclick='mudaDePagina()'>
    
05.09.2016 / 23:38