Sunday, March 8, 2009

Coldfusion send email with attachment

Sending attachment emails are also as easy as sending the text email messages. Just addition you have to do to normal Coldfusion email is that you have to specify the path of file to be attached and you are done. So following is the code to send attachment Email in coldfusion

<cfmail to="address@anysite.com"
from="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

</cfmail>

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.





Coldfusion send text email

Sending email is quite a basic feature now a days which every website need to do. I have done this in PHP as well but I don't think so that there is any other language other than coldfusion which have email sending code smaller than cold fusion. Additionally I will not say it code :-). Its more like piece of a cake. Anyways the code to send email in coldfusion follows as,

<cfmail 
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 :-)

</cfmail>

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.



Tuesday, March 3, 2009

Coldfusion get visitors IP

Here is how you can get the visitor's IP in Coldfusion.

<cfoutput>#CGI.REMOTE_ADDR#</cfoutput>

OR just set a variable with IP like
<cfset userIP="#CGI.REMOTE_ADDR#">

Enjoy!!


HTML tag to display the html code on webpage

The easiest way to show the HTML code on a web page is to use XMP tag. Normally html code is always executed and we can show it using the values of '<' and '>' like &lt_; and &gt_; without the underscores.

But 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.

<xmp>Paste "html code to be shown" here.</xmp>

Enjoy! Your comments are always welcome.



PHP Get the whole query string text from address bar

Previously in a comment a question was asked from me about how to get the text following the URL in title bar.

In PHP you can get the query string text with is separated by URL via '?' character. For this you can use 'query_string' with server variable.

So you can use it like

<?php
echo $_SERVER['QUERY_STRING'];
?>

So, for following URL in address bar:-
www.mobifonz.com?var1=3&var3=this

Output will be:-
var1=3&var3=this

And for following URL in address bar:-
www.mobifonz.com?this_Is_Some_Text

Output will be:-
this_Is_Some_Text

Means it will return anything after the '?' sign.


Sunday, March 1, 2009

javascript select partial text in a div element

Some times we need mechanisms to select(highlight) partial text in a div or td element, lets say on click of a button. So that visitor just right click on selected text and copy the text to paste it anywhere else.

The 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.

<div id="myDiv">
Some text here to be selected...
</div>
<input value="Click Me" onclick="selectText('myDiv','0','500')" type="button">


Above is the way I am calling the code you can always call function on different event according to your requirements.

Enjoy!!!


Javascript Select or Highlight Text Inside Div

This Posts shows how to select the whole text inside 'div' element of a page on button click, so user can just right click the text and copy all of it.

JS 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.


<div id="myDiv">
Some text here...
</div>
<input type="button" value="Click Me" onClick="selectText('myDiv')">



Now your function to select/highlight whole text in a div is implemented.

Enjoy!!

Comments are appreciated.