Using the TextEdit Property : Text Selection « HTML « JavaScript DHTML






Using the TextEdit Property


<HTML>
<HEAD>
<TITLE>parentTextEdit Property</TITLE>
<SCRIPT LANGUAGE="JavaScript">
function selectChunk() {
    var chunk, range
    var x = window.event.clientX
    var y = window.event.clientY

    for (var i = 0; i < document.forms[0].chunk.length; i++) {
        if (document.forms[0].chunk[i].checked) {
            chunk = document.forms[0].chunk[i].value
            break    
        }
    }
    if (window.event.srcElement.parentTextEdit) {
        range = window.event.srcElement.parentTextEdit.createTextRange()
        range.collapse()
        range.moveToPoint(x, y)
        range.expand(chunk)
        range.select()
    }
}
</SCRIPT>
</HEAD>
<BODY BGCOLOR="white">
<FORM>
<P>Choose how much of the paragraph is to be selected when you click anywhere in it:<BR>
<INPUT TYPE="radio" NAME="chunk" VALUE="character" CHECKED>Character
<INPUT TYPE="radio" NAME="chunk" VALUE="word">Word
<INPUT TYPE="radio" NAME="chunk" VALUE="sentence">Sentence
<FONT COLOR="white">.</FONT></P>
</FORM>
<P onClick="selectChunk()">
text text text text text text text text text text text text text text 
</P>
</BODY>
</HTML>


           
       








Related examples in the same category

1.Capturing a Text Selection
2.Using the elementFromPoint() Method
3.Get selected elememnt
4.Get selecte text in one paragraph