Question

In Non-IE browser, Flow Action is submitted when pressing the Enter Key

Upon hitting the enter key on a text input field, the flow action is getting submitted in Non-IE browser. Using 6.3 SP1

The below code works fine in IE but not in Chrome/FF.

function disableEnterKey(e)
{
var key;

if(window.event)
key = window.event.keyCode;

if(key == 13)
return false;
else
return true;

}
document.onkeydown = disableEnterKey;

Correct Answer
May 17, 2018 - 3:30am

Hello ,

I have replicated the issue locally and tried the below code which works fine in every browser:-

<script>
function disableEnterKey(e){

 e = e || window.event || {}; var charCode = e.charCode || e.keyCode || e.which;

if(charCode == 13){

return false;
}

return true;
}

document.onkeydown = disableEnterKey;
</script>

Please try the above code and let us know the update.

Thanks,

Hari

Comments

Keep up to date on this post and subscribe to comments

Pega
May 16, 2018 - 12:30am

Hello ,

I think you have missed some flower braces in the code.Kindly try the below suggested code at your end:-

Code:-

<script>
function disableEnterKey(e){

var key;

if(window.event){
key = window.event.keyCode;
}

if(key == 13){
return false;
}

return true;
}

document.onkeydown = disableEnterKey;
</script>

Copy and paste the above code in your userworkform.

If the above code doesn't help, kindly check this link which provides information about the events and key code in chorme and fire fox browser.

https://www.aspsnippets.com/Articles/Solved-JavaScript-windoweventkeyCode-not-working-in-IE-Mozilla-FireFox-Chrome-Safari-and-Opera.aspx

Hope this helps.

Thanks,

Hari

May 16, 2018 - 2:07pm
Response to Hari Ch

The above code works in Chrome but not in Firefox. I used the below code as per the article but it didnt help. Error is 'key' is undefined. Thoughts?

function GetKeyCode(evt)

    {

        var key;

      

            key = evt.key;

     

        if(keyCode == 13)
          return false;
     else
          return true;
     
   
}
document.onkeypress = GetKeyCode(event);

Pega
May 16, 2018 - 9:34pm
Response to Khnb38

There are some errors in your code. Modified the code below:-

function GetKeyCode(evt)

{

var key;

 

key = evt.keyCode;

 

if(key == 13)
return false;
else
return true;

}
document.onkeypress = GetKeyCode(event);

Try the above code once.

Thanks,
Hari

May 16, 2018 - 10:11pm
Response to Hari Ch

Tried the above code. In the web console of the browser, I am seeing JS error: - ReferenceError: event is not defined

Any idea where/how to define the event that is being passed in the function?

Pega
May 17, 2018 - 3:30am
Response to Khnb38

Hello ,

I have replicated the issue locally and tried the below code which works fine in every browser:-

<script>
function disableEnterKey(e){

 e = e || window.event || {}; var charCode = e.charCode || e.keyCode || e.which;

if(charCode == 13){

return false;
}

return true;
}

document.onkeydown = disableEnterKey;
</script>

Please try the above code and let us know the update.

Thanks,

Hari