Created
April 28, 2017 11:20
-
-
Save cuduy197/7b7ed5927b54df420c2b8fb89c1430f6 to your computer and use it in GitHub Desktop.
Get selected text in textarea !!!!!!!!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<meta name="viewport" content="width=device-width"> | |
<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css"> | |
<title>Get selected text </title> | |
</head> | |
<body> | |
<form class="w3-container"> | |
<h2>Selected text : </h2> | |
<mark id="result"></mark> | |
<br> | |
<hr> | |
<textarea onclick="showResult()" class="w3-input w3-animate-input" rows="4" cols="50" style="width:100%" > | |
At w3schools.com you will learn how to make a website. We offer free tutorials in all web development technologies. | |
</textarea> | |
</form> | |
<script> | |
function getText(input) { | |
return input.value.substring(input.selectionStart, input.selectionEnd); | |
} | |
function showResult() { | |
var selectText = getText(document.getElementsByTagName("textarea")[0]); | |
var selectText = getText(document.getElementsByTagName("textarea")[0]); | |
document.getElementById('result').innerHTML = selectText; | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment