ColdFusion Ajax & JQuery ... Learn to Earn

Recently I decided that it's time to start paying a bit more attention to improving the visual presentation of one of my sites. The site's built in ColdFusion with lot's of nifty CF Ajax stuff thrown in. CFDiv's, CFWindows, and Pods here and there too. So, I figured since I'm not too bad at coding in CF - at least I can usually Google my way through most of the snags I run in to - I wanted to try challenging myself a bit by taking on something fairly foreign to me. Ajax.

I know the basics of Ajax. Asynchronous JavaScript with XML - Sending and receiving Http requests and responses to a server to return data to a site without refreshing the documents. However, I had little experience actually taking on an Ajax project. But if that wasn't difficult enough, I wanted to get really frustrated, so I decided to use a JavaScript library that I had little if any experience with - Entrance JQuery.

Now I've seen a lot of very groovy examples of the nifty UI tricks that can be done with JQuery. They are cool. But I really wanted to learn how to use JQuery for my specific needs. So, I did. I choose to launch my campaign with a real world example. So for my project, I mapped out what I wanted to do with ColdFusion, JQuery, and Some CFAjax stuff. Here's what I planned out ... First, I wanted to add a US database to my site, SEOMasterList.com, to build out some dynamic pages. The reasons for that should be quite apparent. I'm planning to obtain rankings and possibly monetize the site.

Next, I wanted to add some cool visual effects while providing improved functionality to the site, and possibly give visitors a better experience.

And finally, I just wanted to see if I could actually do it - two weeks in to it, I finished it. I have got to admit I spent a hell of a lot of time learning while trying to get the site done - someone with experience could have probably launched it in a matter of no time. But, I learned a lot.

Once I modified, installed, and built out the components to accommodate the addition of the database, I set up another component to dynamically bind the results from the database to two selects in a form. This was very challenging - I spent the better part of two days just trying to get the bindings to work. Luckily, I found a cool ColdFusion script and modified it to output my database queries to XML. That came in really handy. The first go at trying to output 80,000+ records to a single flat XML file didn't work out to well. I ended up rebuilding the data CFC's several times in order to get what I needed. I ended up with a 1.4 MB XML file that I'm now using to bind to the data in the selects.

After tackling that part of the project, I wanted to introduce some visually appealing effects to the site so I picked up the latest JQuery code and sent it up to my site. After some effort, I was successful in creating a pretty slick interface for my Ajax loaded form. Through the use of some nifty ('#div').show(),('#div').hide () functionality on the form page, I was able to add and remove elements of the page which weren't necessary at every stage of the form submission process. This proved to be tougher to implement than I had expected. Up to this point I have a form bound by CFC's to data, an asynchronous form handler to process a form submission, and some nifty JQuery going on to assist in dressing up my application modifications. All in all. I think it went really well - and I learned a whole hell of a lot doing it. If you want to see what I did ... have a heart ... I'm an Ajax nOOb. Check it out on SEOMasterList ...

SQL UDF to Convert Uppercase to Propercase

So, I figured that it would be a good idea to try and expand Florida Search Engine Optimization web coverage beyond the Miami, Fort Lauderdale areas. So, I started a project to build a quazi regional network in my site. At first, I tried to be creative and store all of the cities and counties of Florida in an array with the counties as an array of structs.

With some work, I was able to get this running. However, I realized that if and when I want to make changes or additions to the cities or counties, it was going to be quite a bit of work.

After some consideration I decided that it would be much easier to just use a database table with the cities and counties.

Now, everything was going quite well with the addition of the new database when I found that the city and county fields were all in uppercase ... I really didn't want to leave the data like that, so I decided to figure out how to change the 80,000 plus records to propercase, and I found just the thing ... a cool little T-SQL UDF ... that changes the data to propercase ... the code follows ...

create FUNCTION PROPERCASE
(
--The string to be converted to proper case
@input varchar(8000)
)
--This function returns the proper case string of varchar type
RETURNS varchar(8000)
AS
BEGIN
IF @input IS NULL
BEGIN
--Just return NULL if input string is NULL
RETURN NULL
END

--Character variable declarations
DECLARE @output varchar(8000)
--Integer variable declarations
DECLARE @ctr int, @len int, @found_at int
--Constant declarations
DECLARE @LOWER_CASE_a int, @LOWER_CASE_z int, @Delimiter char(3), @UPPER_CASE_A int, @UPPER_CASE_Z int

--Variable/Constant initializations
SET @ctr = 1
SET @len = LEN(@input)
SET @output = ''
SET @LOWER_CASE_a = 97
SET @LOWER_CASE_z = 122
SET @Delimiter = ' ,-'
SET @UPPER_CASE_A = 65
SET @UPPER_CASE_Z = 90

WHILE @ctr <= @len
BEGIN
--This loop will take care of reccuring white spaces
WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) > 0
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
SET @ctr = @ctr + 1
END

IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @LOWER_CASE_a AND @LOWER_CASE_z
BEGIN
--Converting the first character to upper case
SET @output = @output + UPPER(SUBSTRING(@input,@ctr,1))
END
ELSE
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
END

SET @ctr = @ctr + 1

WHILE CHARINDEX(SUBSTRING(@input,@ctr,1), @Delimiter) = 0 AND (@ctr <= @len)
BEGIN
IF ASCII(SUBSTRING(@input,@ctr,1)) BETWEEN @UPPER_CASE_A AND @UPPER_CASE_Z
BEGIN
SET @output = @output + LOWER(SUBSTRING(@input,@ctr,1))
END
ELSE
BEGIN
SET @output = @output + SUBSTRING(@input,@ctr,1)
END
SET @ctr = @ctr + 1
END

END
RETURN @output
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

So all that was required to get this to work, was to call the UDF after it was created ...

END
RETURN @output
END

GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO

--Insert your call here ...
UPDATE TABLENAME
SET fieldname=dbo.PROPERCASE(fieldname)
FROM DBNAME..TABLENAME

Now this saved me a hell of a lot of time and was a very simple and easy way to format the data the way that I wanted. Unfortunately, when I went to repeat the same action for the counties, I accidentally wrote over the city fields with the data in the counties field ... Smooth.

It would really come in handy if something like this could have been done in ColdFusion without having to create a UDF to do so ... maybe the guys over at Adobe will read this and decide that it merits inclusion into the next release.

BlogCFC was created by Raymond Camden. This blog is running version 5.9. Contact Florida Search Engine Optimization L.L.C.
Search Engine Optimization Specialist || Web Designer || Web Developer || Edward J Beckett ||
Search Engine Optimization Company  || SEO Services || Internet Marketing Company || Search Engine Optimization Expert || Florida Search Engine Optimization LLC
Florida Search Engine Optimization || Search Engine Optimization || SEO Services || Florida SEO Blog
Florida Search Engine Optimization
Search Engine Optimization
SEO Services
Florida SEO Blog
August-01-2010
2:17 AM EST