Javascript to Select or Highlight Text Inside Div
Posted On at by milanJS function.
function selectText(divID) //divID contains actual id of 'div' element
{
var textC=document.getElementById(divID);
if (document.selection)
{
//Portion for IE
var div = document.body.createTextRange();
div.moveToElementText(textC);
div.select();
}
else
{
//Portion for FF
var div = document.createRange();
div.setStartBefore(textC);
div.setEndAfter(textC);
window.getSelection().addRange(div);
alert(div.value);
}
}
Now add this above function to js file being included in the page where you have to implement the text highlight inside the div. Or make a .js file put this function inside upload to some location and include to html file. Also you can choose to add above function to head section of HTML via javascript tag.
Now following is the way to call it.
Some text here...
Now your function to select/highlight whole text in a div is implemented.
Enjoy!!
Comments are appreciated.
code of javascript to select partial text in a div element
Posted On at by milanThe code I am going to publish selects the div elements on the base of starting character and length of div text.
Lets say if you want to select first 500 characters in div you will provide the "start" argument as 0 and length as 500.
Similarly, you can choose to select(highlight) the text form 100th character to 600th in the div. In this case you will provide the "start" as 100 and "length" as 600. First argument will be id of div element in which text is to be select.
Lets go to the actual code now. here goes the select text function.
function selectText(ID, start, length)
{
if (document.selection)
{
//Code for IE and few other
document.selection.empty();
var textC = document.getElementById(ID);
var div = document.body.createTextRange();
div.moveToElementText(textC);
div.setEndPoint("EndToEnd", div);
div.moveStart('character', start);
if(length + start>textC.innerHTML.length)
length=textC.innerHTML.length-start;
div.moveEnd('character', -(textC.innerHTML.length - start - length));
div.select();
}
else
{
//code for FF and few other
window.getSelection().removeAllRanges();
var textC = document.getElementById(ID);
while ( textC.hasChildNodes() ) textC = textC.childNodes[0];
var div = document.createRange();
div.setStart(textC, start);
if (start+length > textC.length) length = textC.length - start;
div.setEnd(textC, start+length);
window.getSelection().addRange(div);
}
return false;
}
Now this is how we will implement this in HTML for lets say selecting first 500 characters in this case.
Some text here to be selected...
Above is the way I am calling the code you can always call function on different event according to your requirements.
Enjoy!!!
code to HTML tag to display the html
Posted On at by milanBut XMP tag method is more convinient. The html code you want to show on a webpage just surround it with XMP code and thats it.
Enjoy! Your comments are always welcome.
code of Coldfusion send text email
Posted On at by milan
to="email@site.com"
cc="address2@site.com"
bcc="anyaddress@site.com"
from="sender@site.com"
subject="Check this out" type="text">
Dear Friend,
I have searched out a good website which says it all about coding.
I would like you to check it out.
Site is: http://codingtricks.blogspot.com
Regard,
Mail Sender :-)
Keep enjoying and keep checking lots of Cold Fusion, PHP and related posts ahead.
Coldfusion send email with file attachment is also coming up in the queue.
Coldfusion send text email ecerywere
Posted On at by milan
to="email@site.com"
cc="address2@site.com"
bcc="anyaddress@site.com"
from="sender@site.com"
subject="Check this out" type="text">
Dear Friend,
I have searched out a good website which says it all about coding.
I would like you to check it out.
Site is: http://codingtricks.blogspot.com
Regard,
Mail Sender :-)
Keep enjoying and keep checking lots of Cold Fusion, PHP and related posts ahead.
Coldfusion send email with file attachment is also coming up in the queue.
Coldfusion send email with attachment file
Posted On at by milanfrom="sendersaddress@anysite.com"
subject="my first email with attachment"
type="text"
mimeattach="subfolder/folder/mypdf.pdf"> (path of file, which is to be attached)
hi,
This is me sending you attached file.
Bye,
sender
Have you just witnessed how easy it is to send attachment email in coldfusion. In PHP it will be code of atleast 50 lines, you can explore my blog for finding PHP equallent. Bookmark this page and blog to check back.
Now enjoy.