Using the select() method to select content of a text field. to trigger onselect event - Javascript DOM Event

Javascript examples for DOM Event:onselect

Description

Using the select() method to select content of a text field. to trigger onselect event

Demo Code

ResultView the demo in separate window

<!DOCTYPE html>
<html>
<body>

<input type="text" id="myText" value="Some text.." onselect="myAlertFunction()">

<button type="button" onclick="mySelectFunction()">Select content</button>

<script>
function mySelectFunction() {//  www. j av a 2  s  . c o m
    document.getElementById("myText").select();
}

function myAlertFunction() {
    console.log("You selected some text!");
}
</script>

</body>
</html>

Related Tutorials