The CreatorCon Call for Content is officially open! Get started here.

how to use DOM KeyboardEvent in Servicenow?

Sharique Azim
Mega Sage

Hi, 

Can anybody help me realise ,how exactly can i implement the DOM KeyboardEvent functionality in servicenow.

I am trying to select some form elements(may not be fields,but html elements) and perform some action whenever i hit any keyboard button.

demo of what i mean

1 ACCEPTED SOLUTION

Harsh Vardhan
Giga Patron

i checked your w3schools code and added to the UI Page and it's working.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<body>

<p>Press any key on the keyboard in the input field to get the Unicode character code and the Unicode key code of the pressed key.</p>

<p><strong>Note:</strong> The which and keyCode property does not work on the onkeypress event for non-printable, function keys (like CAPS LOCK, CTRL, ESC, F12, etc.).</p>

	<input type="text" size="50" onkeypress="uniCharCode(event)" onkeydown="uniKeyCode(event)"> </input>

<p>onkeypress - <span id="demo"></span></p>
<p>onkeydown - <span id="demo2"></span></p>

<script>
function uniCharCode(event) { 
    var char = event.which || event.keyCode; 
    document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char;
}

function uniKeyCode(event) {
    var key = event.which || event.keyCode; 
    document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key;
}
</script>

</body>

</j:jelly>

 

 

find_real_file.png

View solution in original post

3 REPLIES 3

Harsh Vardhan
Giga Patron

in service-now where exactly have you written ?

Harsh Vardhan
Giga Patron

i checked your w3schools code and added to the UI Page and it's working.

 

<?xml version="1.0" encoding="utf-8" ?>
<j:jelly trim="false" xmlns:j="jelly:core" xmlns:g="glide" xmlns:j2="null" xmlns:g2="null">
<body>

<p>Press any key on the keyboard in the input field to get the Unicode character code and the Unicode key code of the pressed key.</p>

<p><strong>Note:</strong> The which and keyCode property does not work on the onkeypress event for non-printable, function keys (like CAPS LOCK, CTRL, ESC, F12, etc.).</p>

	<input type="text" size="50" onkeypress="uniCharCode(event)" onkeydown="uniKeyCode(event)"> </input>

<p>onkeypress - <span id="demo"></span></p>
<p>onkeydown - <span id="demo2"></span></p>

<script>
function uniCharCode(event) { 
    var char = event.which || event.keyCode; 
    document.getElementById("demo").innerHTML = "The Unicode CHARACTER code is: " + char;
}

function uniKeyCode(event) {
    var key = event.which || event.keyCode; 
    document.getElementById("demo2").innerHTML = "The Unicode KEY code is: " + key;
}
</script>

</body>

</j:jelly>

 

 

find_real_file.png

Although i realised i was making a typo error, i would still mark ir correct. thanks for your efforts.