Saturday, June 04, 2005

Coldfusion Stripping Out Special Characters

I have variables being passed through a URL and automatically populated in form fields in a CFM page. However, when the variable value has a quotation mark it won't populate the field properly... I expect it is because the quotation is forcing the value="" attribute in the form to terminate prematurely.

How can I strip special characters from CF variables as they are passed to the CF template?

<input type="MyField" value="#URLEncodedFormat(URL.VarA)#">

If that doesn't work... <input type="MyField" value="#Replace(URL.VarA,Chr(34),""e;","ALL")#">

Friday, June 03, 2005

Javascript for Stopping Email Harvesting

I need a Javascript that will stop email harvestng.

<script type="text/javascript" language="javascript">
var user = "address";
var domain = "";
function email()
location.href=("mail" + "to:" + user + "@" + domain);

Thursday, June 02, 2005

Add To My Favorites

Is there a snippet of code that will enable me to make a link that will add a site to My Favorites in Internet Explorer?

<form><input type="button" value="Add to Favorites" onClick='window.external.AddFavorite(location.href, document.title);'></form>

Wednesday, June 01, 2005

How Do I Make A Page That Redirects The User

I use this above the /head tag:
<meta http-equiv="refresh" content="0;URL=YOUR URL GOES HERE">

Tuesday, May 31, 2005

Print Button

I have a form which goes to an action page outputting the results of the form.

On this form I would like to have a "print" button so a person can just click on this button and have the information print out.

<form><input type="button" name="printbttn" value="Print" onClick="window.print();"></form>

Monday, May 30, 2005

Cursor In The Form Field?

Ever wondered how they get the cursor to automatically flash in the first input field of a form?

In order for a user to fill out a form field, he/she must first give it focus. This is achieved by clicking in the form field. Only then can they enter their data. This snippet will automatically give focus to the first form field.

Take the contents below and add it to the <head> area of your webpage. Then replace your <body> tag with the complete <body onload="setfocus()"> tag below. That's it. The form that is shown below is an example that you can use to test the effectiveness of this little script.

<script type="text/javascript">
function setfocus()

<body onload="setfocus()">
<input type="text" name="field" size="30">
<input type="text" name="field1" size="30">
<input type="text" name="field2" size="30">
<input type="text" name="field3" size="30">
<input type="text" name="field4" size="30">

Using techniques like this one make your site easier to use, one of a webmaster's main goals. When you are asking a person to fill out a form you should save them a mouse click by predicting their needs and providing 'focus' to the first field in your form automatically.

Sunday, May 29, 2005

Stripping Text from Strings With Coldfusion

I am attempting to delete a string from a file using <CFFILE> and Replace(). It works fine except that there is a gaping "hole" left in my string where the string should close up.

<!--- Open File --->
<cffile action="read" file="/mypath/myfile.txt" variable="myfile_Original">

<!--- Replace Changed String --->
<cfset myfile_Updated = Replace(myfile_Original, "Delete this line of text please!", "")>

<!--- Write Changed File --->
<cffile action="write" file="/mypath/myfile.txt"
output="#myfile_Updated#" addnewline="no">

How can I delete a string of words in a file without having it leaving any space, CRLF etc. ?

Replace duplicate CRLF's with a single CRLF.

<CFSET cr=Chr(13) & Chr(10)>
<CFSET Txt=Replace(Txt,cr & cr,cr,"ALL")>