<!DOCTYPE html>
<html>
<body>
Select some of the text: <input type="text" value="Hello world!" onselect="myFunction()">
<script>
function myFunction() {
alert("You selected some text!");
}
</script>
</body>
</html>