Если правильно понял...
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8" />
<title></title>
</head>
<body>
<textarea cols="30" rows="10">bla-bla-bla</textarea>
<input type="text" value="bla-bla" />
<p>Lorem ipsum dolor sit amet, consectetur adipisicing elit. Rem, esse architecto impedit adipisci assumenda nulla, eligendi minus ipsam optio ea iusto accusamus expedita sunt natus iste ipsum consectetur nostrum! Doloribus.</p>
<button id="btn">To get selected text</button>
<script>
var b = document.getElementById('btn');
var a = '';
b.onclick = function() {
a && alert( a );
a = '';
};
document.onmouseup = function(e) {
if (e.target.tagName.toLowerCase() == 'textarea' ||
e.target.tagName.toLowerCase() == 'input') {
a = window.getSelection().toString();
}
};
</script>
</body>
</html>