26
Category: JavaScript
Getting the selected text from text area by JavaScript

During the development of web sometime we need to develop a small text editor embedding a text area into HTML document and for those we have to do browser end program and so to code javascript is common approach to do so

We can write a simple code using HTML DOM for it as below


<html>
<head >
<script>
function displayResult()
{
document.getElementById("myTextarea").select();
}
</script>
</head>
<body>

<textarea id="myTextarea" cols="20">
All these are actually Javascript model with object referenced code.
</textarea>
<br>

<button type="button" onclick="displayResult()">Select contents of text area</button>

</body>
</html>