Calling a javascript to action on a keyboard enter key event
Hello,
I have a section A where I use Auto-generated HTML and another section B in which I use hard coded HTML. In here, I create a java script which can be called from Section A and execute the same behaviour of a button (which resides in section A) when clicked. The javascript should capture the enter key when hit on the keyboard and simulate the behaviour of the button click.
In Section A I am using a section rule within a layout which refers to Section B. When I test this functionality and I hit the enter key the alert message is popping up as expected but the event click on the button never occurs.
It looks like an issue on passing the button id as whichever id I have tested it with, I always get null id (testing it with the commented out line of codes below).
Both sections are saved in the same ruleset version under Data-Portal CL. We are using Pega 7.1.8 in our project.
Can anyone help me on this please? In previous versions of Pega (6.x) I could easily plug any HTML code or javascript on an existing HTML rule, but in Pega 7 I am not able to see and modify the HTML code of a Harness, Section, etc.
Below is the java script I am using in Section B:
<SCRIPT TYPE="text/javascript">
$(document).keypress(function(event){
var keycode = (event.keyCode ? event.keyCode : event.which);
if(keycode && keycode == '13'){
alert('You pressed a "enter" key in somewhere');
document.getElementById('Submit').click();
/* var btn = document.getElementById('button');
alert (btn); */
}
});
</SCRIPT>
<div onKeyPress="return keypress(event)">
Thanks a lot in advance.