View Full Version : validation for highlited text

06-12-2003, 04:43 PM
I am building simulation. User has to highlite text and copy it. So the copy command would be available only after user highlites text. Is it possible to validate text field for highliting? Another word how could I check if all text in a field is highlited?

Thank you for any ideas.

06-12-2003, 08:16 PM
You can check to see the lenght of the text range selected and the length of the text in the element it was selected from.

06-12-2003, 08:35 PM
Not a bad idea, A1ien51, thank you. Actually this solution would work for me, I just have to modify it:


Other text on document<BR>
<form name=exf1>
<textarea name="t1" rows=2 cols=20 >Some default text</textarea>
<BR><input type=button onclick="gettext()" value="Show selected text!">
function gettext(){
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
alert (rng.text);