Using the TextEdit Property : Text Selection : HTML : JavaScript DHTML examples (example source code) Organized by topic

JavaScript DHTML
C++
PHP
JavaScript DHTML Home »  HTML   » [  Text Selection  ]   
 



Using the TextEdit Property

Please note that some example is only working under IE or Firefox.


/*
JavaScript Bible, Fourth Edition
by Danny Goodman 

John Wiley & Sons CopyRight 2001
*/

<HTML>
<HEAD>
<TITLE>parentTextEdit Property</TITLE>
<STYLE TYPE="text/css">
{cursor:hand}
</STYLE>
<SCRIPT LANGUAGE="JavaScript">
function selectChunk() {
    var chunk, range
    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    
        }
    }
    var x = window.event.clientX
    var y = window.event.clientY
    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()">
Lorem ipsum dolor sit amet, consectetaur adipisicing elit, sed do eiusmod tempor
 incididunt ut labore et dolore magna aliqua. Ut enim adminim veniam, quis
 nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat.
 Duis aute irure dolor in reprehenderit involuptate velit esse cillum dolore eu
 fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in
 culpa qui officia deserunt mollit anim id est laborum.
</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








Home| Contact Us
Copyright 2003 - 04 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.