<html>
<body>
<p>Use the HTML DOM to assign an "onselect" event to an input element.</p>
Select some text: <input type="text" value="Hello world!" id="myText">
<p id="demo"></p>
<script>
document.getElementById("myText").onselect = function() {myFunction()};
function myFunction() {
document.getElementById("demo").innerHTML = "You selected some text!";
}
</script>
</body>
</html>