...

View Full Version : how to get the selected text



kamarthi7
06-06-2003, 10:22 AM
hello,

can anybody please tell me how to get the selected text in a document.

when some text is selected I want to show the text in an alert box.

hope it is posible,


ANIL

arnyinc
06-06-2003, 03:38 PM
This will get you halfway (from http://www.xs4all.nl/~ppk/js/selected.html)


<html>
<head>
<script language="javascript">
function getSel(){
if (document.getSelection) txt = document.getSelection();
else if (document.selection) txt = document.selection.createRange().text;
else return;

alert(txt.replace(new RegExp('([\\f\\n\\r\\t\\v ])+', 'g')," "));
}

</script>
</head>
<body>
<form>
lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
lskdfas dflkjasdflkj hsdakjf hsadhf asd;lkjf s;lkdfj;lkas jfdlkasjd fkjsahfd kljahf p98wefh p9ewh0f27f hqwhfe audsnf oiwuhf 9hf 9dw8hf <br><br>
<input type="button" onclick="getSel();" value="show text">
</form>
</body>
</html>

kamarthi7
06-06-2003, 05:27 PM
thanks a lot friend that was really useful...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum