Javascript DOM onkeyup Event via HTML Tag onkeyup function

Introduction

In JavaScript:

object.onkeyup = function(){
       myScript};

This example uses the HTML DOM to assign an "onkeyup" event to an input element.

Press a key inside the text field and release it to set the text to uppercase.

View in separate window

<!DOCTYPE html>
<html>
<body>
Enter your name: <input type="text" id="fname">

<script>
document.getElementById("fname").onkeyup = function() {myFunction()};

function myFunction() {/*  w  w w  .  j  av a  2 s.  c  o  m*/
  var x = document.getElementById("fname");
  x.value = x.value.toUpperCase();
}
</script>

</body>
</html>
Bubbles:
Cancelable:
Event type:
Supported HTML tags:












Yes
Yes
KeyboardEvent
All HTML elements,
EXCEPT:
<base>,
<bdo>,
<br>,
<head>,
<html>,
<iframe>,
<meta>,
<param>,
<script>,
<style>, and
<title>



PreviousNext

Related