Assuming that a sentence is defined as the text between two periods, then this will do the trick.
Code:
<html>
<head>
</head>
<body>
<div id = "myLorem">
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Etiam ipsum leo, scelerisque at dapibus ac, consectetur vel ipsum. Morbi et metus ut diam molestie ullamcorper. Suspendisse rutrum neque semper. Donec volutpat neque in lorem tempus scelerisque. Curabitur dignissim rhoncus quam ac suscipit. Donec viverra quam lobortis neque porta a sagittis urna tristique. Suspendisse nec lacus nisi. Pellentesque fermentum massa sit amet magna hendrerit vestibulum. Sed elit libero, scelerisque eu eleifend ut, interdum gravida nunc. Etiam ut nisi sapien, et tempus sem. Nam vel mi est. Mauris congue felis ut ante bibendum vehicula. Nullam nec sapien arcu, eget cursus lorem. Donec blandit, dolor tristique ornare dictum, arcu sapien vulputate dolor, et placerat risus odio ut magna. Ut magna mauris, pellentesque at ultricies vitae, fermentum vitae dolor.
</div>
<form name= "myform">
<textarea name = "txtarea" rows = "10" cols = "55"></textarea><br>
<input type = "button" value = "Capture Sentence Containing Highlighted Text" onclick = "getActiveText()">
<input type = "button" value = "Clear" onclick = "document.myform.txtarea.value = ''">
</form>
<script type = "text/javascript">
var x = document.getElementById("myLorem").innerHTML;
var text = "";
function getActiveText(e) {
text = (document.all) ? document.selection.createRange().text : document.getSelection();
var firstPos = x.indexOf(text);
var secondPos = x.indexOf(".", firstPos + 1);
var newtext = x.substring(firstPos, secondPos+1);
var start = 0;
for (var i = firstPos; i > 0; i-- ){
var the_char = x.charAt(i);
if (the_char == ".") {
start = i+2;
break;
}
}
newtext = x.substring(start, firstPos) + newtext;
document.myform.txtarea.value = newtext;
return true;
}
</script>
</body>
</html>
BTW, the time to say "thanks" is afterwards, not beforehand which gives the - doubtless unintended - impression that you take other people's voluntary unpaid assistance and expertise for granted. Or as British politician Neil Kinnock put it, "Don't belch before you have had the meal." Prefer to use "please" beforehand and if you find a response helpful then you can use the "Thank User For This Post" button.
"I have not failed. I've just found 10,000 ways that won't work. " - Thomas Edison