...

View Full Version : validation for highlited text



chelentano
06-12-2003, 05: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.

A1ien51
06-12-2003, 09: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.

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

<body>

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!">
</form>
<script>
function gettext(){
var sel = document.selection;
if (sel!=null) {
var rng = sel.createRange();
if (rng!=null)
alert (rng.text);
}
}
</script>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum