I'm building a form
and i'd like to make my radio button
behave like i've pressed Enter
something like onclick="keycode=13"
any idea how to do ?
I'm building a form
and i'd like to make my radio button
behave like i've pressed Enter
something like onclick="keycode=13"
any idea how to do ?
If you wanna submit the form, you can just attach the click handler to submit the form.
<input type="radio" onclick="this.form.submit();" />
Or you an even trigger the enter key!
<input type="radio" onclick='e = jQuery.Event("keypress"); e.which = 13; e.keyCode = 13; this.trigger(e);' />
In your event handler you can submit a form using the following code:
document.getElementById("myForm").submit();
Add onkeypress on your form:
<form .. onkeypress="return myEvent(event)">
<input type="radio" id="myRadio">
Than add Javascript
<script type="text/javascript">
function myEvent(e) {
e = e || window.event;
var key = e.keyCode || e.charCode;
if (key === 13) {
// enter down
document.getElementById('myRadio').checked = true;
return false; // prevent form post on enter
}
return true;
}
</script>
I think the code above should work, because I have very similar code to prevent form post on Enter press.
Bit late, however...
<form name="myform">
<input type=radio onclick="this.parentNode.submit()">click</input>
</form>
i managed to achieve this by adding the followind code to the script
document.addEventListener( 'click', function( ev ) {
ev.preventDefault();
self._nextQuestion();
} );