0

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 ?

Farshad
  • 1,465
  • 1
  • 9
  • 12
Jérémie Zarca
  • 105
  • 1
  • 9

5 Answers5

4

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);' />
Praveen Kumar Purushothaman
  • 164,888
  • 24
  • 203
  • 252
0

In your event handler you can submit a form using the following code:

document.getElementById("myForm").submit();
Jonathan Sayce
  • 9,359
  • 5
  • 37
  • 51
0

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.

JercSi
  • 1,037
  • 1
  • 9
  • 19
0

Bit late, however...

<form name="myform">
    <input type=radio onclick="this.parentNode.submit()">click</input>
</form>
Unrealsolver
  • 143
  • 4
-1

i managed to achieve this by adding the followind code to the script

document.addEventListener( 'click', function( ev ) {

            ev.preventDefault();
            self._nextQuestion();
    } );
Jérémie Zarca
  • 105
  • 1
  • 9