0

i have this code:

<a href="#openModal">Open Modal</a>
<div id="openModal" class="modalDialog">
<div>
    <a href="#close" title="Close" class="close">X</a>
    <h2>Modal Box</h2>
    <input type="radio" value="rdRec" checked="checked" />Rec
    <input type="radio" value="rdPot" />Pot
    <input type="button" id="btnOk" value="ok" onkeypress="checkey();">
</div>

<script type="text/javascript">
  function checkey()
  {
     var code = window.event.keyCode;
     if(code == 13) 
     {      
     document.getElementById('btnOk').click();
     return false;
     }
  }
</script>

All i want is when the popup is open and the radio button Rec is select/checked i want to click on enter key and automatically trigger the btnOk...

Erased
  • 221
  • 1
  • 10
  • I think the answer you're looking for is in this previously answered question: http://stackoverflow.com/questions/382171/use-javascript-to-change-which-submit-is-activated-on-enter-key-press – DenizEng Feb 21 '16 at 00:20
  • Possible duplicate of [detect key press on modal dialog not working](https://stackoverflow.com/questions/34351044/detect-key-press-on-modal-dialog-not-working) – Vic Seedoubleyew Jul 18 '19 at 14:23

1 Answers1

0

I think the answer you're looking for is in this previously answered question: Use Javascript to change which submit is activated on enter key press

document.onkeypress = processKey;

function processKey(e)
{
    if (null == e)
        e = window.event ;
    if (e.keyCode == 13)  {
        document.getElementById("btnOk").click();
    }
}
Community
  • 1
  • 1
DenizEng
  • 400
  • 4
  • 14