Selecting an option in a select tag based on value - jQuery's .attr to the rescue!

I am working on a ColdFusion site for a friend's business, and I needed to have a list of states in a pulldown on a page in the admin section. This is easy enough to populate for the add form with a quick search on the web, but when you have to select the option tag on the edit form, it gets a bit tricky. When looking for how to do this and not put a <cfif> in every option tag, I came across some .cfc solutions like this:

http://www.webveteran.com/blog/index.php/web-coding/coldfusion/coldfusion-function-display-a-us-states-pulldown-menu/

And that's great, but I thought it should be easier. I'm already using jQuery on the site...couldn't I use it to select the proper option based on value? Why yes. And I did.

Instead of a page full of code, this is how I did it:

$("#state option[value='<cfoutput>#getDetails.state#</cfoutput>']").attr("selected", "selected");

That's it. One line of code. My select element has an id of "state". So I'm selecting that select element, then an option element based on its value which I get from my recordset for that page. Then I just assign the attribute "selected" with the value "selected" and viola!

I love jQuery.

Content aware in CS5...only some content, apparently.

Tried another image in PS CS5 with content aware fill. This one didn't work out so well. Seems like open areas work best for content aware fill. Check out this test. Here's the before...an image my fiancee snapped which on the way to dinner with friends on Saturday night:

And now see the content aware fill on the marquee:

Not so great in this case. So, once again, a great tool in many situations, but not a voodoo magic magic filter as some of us may had thought.

First batch of images using new CS5 features in Photoshop

I downloaded and installed the trial version of CS5 Web Premium while I wait for my serial number to show up snail mail style. I thought I'd do a quick (like 2 minutes quick) test on content aware fill and refine edge. As a developer with somewhat limited photoshop skills I'm definitely interested in these features.

Here is the original image I used. Not the best for these tests what with the water and all, but I thought I'd see what PS can do.

First I decided to use refine edge and cut the dolphin out. Then I stuck in a new background. This is rough, but it only took 1 minute to make a selection then refine the edge.

Next I wanted to try content aware fill. I drew a selection around the dolphin and the water distortions with the lasso tool and selected edit > fill.

I'm just as amazed as I was when I first saw the demo. Can't wait to play with the other new stuff and the rest of the apps in CS5 Web Premium!

Reflections after a subbing gig

I played drums tonight with a band whose regular drummer was out of town. I got the call from a bass player friend of mine who I had played with in another band. It was great fun, and I had a few thoughts on the drive home.

1) This was the first time I had played in public with these guys, and we pretty much killed it. We had one rehearsal earlier in the week, and not all of the original material was recorded or written out.

2) Although my last band didn't work out in the end, I did meet the bass player of this new band there, and I never would have gotten this gig if it weren't for him. Chalk another one up for "ya gotta know somebody."

3) I may or may not play with these guys again, but I'm proud of the gig, and they really seemed to like my playing.

4) People were dancing and having fun, and I had one absolutely bat-shit crazy woman tell me that I "embodied the music of the South", moved her to tears, and would become a multi-millionaire in 3 years time. She also said I was the pretty boy. That's how I knew she was bat-shit crazy.

It's something different and new, and there seem to be a lot of changes in my life at the moment. I had a great time, but I put in the work. I listened to the tunes, wrote charts, and practiced. Well, OK, I only practiced for a few minutes but there is such a thing as practicing without your instrument. After 20+ years of gigging I better know how to play cold by now.

This kind of thing relates to almost anything in life. Put in the work, and do your thing. People will appreciate it. Not everyone, mind you, but the people who really matter will. Your boss might not recognize your hard work sometimes, but he may be a small minded turd, too.

My point is this: Try new things, take chances, put in the work, and go and do it. You may surprise yourself. I've always said that you have to "do what you gotta do to do what you wanna do." I heard that said back to me tonight by a new friend and it's never been more true than right now. Although you need to put in the time and endure some nonsense, in the end you can do your thing and that is where you find your happiness.

 

A new web host

This week I changed web hosts for one of my domains. I've been with GoDaddy for several years and they've been fine for domain registration, basic windows/linux hosting, ColdFusion (even with tags disabled), and email. I still use them for basic hosting of sites on windows with ColdFusion and SQL Server for clients, client email, and all of my domains. But this week I wanted to get URL rewriting working on linux using mod_rewrite and it just wasn't happening.

I was pulling my hair out for two days trying to get the most basic of basic rewrite rules working on GoDaddy:

RewriteRule ^(.*)$ $1.cfm [L]

It just wouldn't work. I'm not saying that's only rule I was trying to use. It's a little more complicated than that to remove file extensions, of course. But just getting this one simple rule to work was driving me insane. And I couldn't get any straight answers from GoDaddy or people on the boards. Not to mention ExpressionEngine URL rewriting was practically non-existent. I had to force query strings, and that's just breaking the deal for me.

So I decided to move my business site away from the cheap but stable GoDaddy to the cheap, stable, and flexible HostingNexus. I wanted a linux based server with mod_rewrite enabled, ColdFusion installed, and remote access to mySQL. It's surprisingly hard to find that combination in a shared hosting provider. I had seen HostingNexus before but I had dismissed them for some reason. I saw them again after @anton saw my plea on Twitter for recommendations for a host. They have a 30 day money back guarantee, so I figured I'd sign up and check it out while my current host was still active.

After a few hours of waiting, my site was ready to go. I started by uploading my current site into the web root, and ExpressionEngine into a subdirectory. I then went to look at the site to make sure things were appearing and I realized that I could not go to an IP to see the site. I wrote a quick email to support and they gave me a workaround to see the site without a domain hooked up. I only waited for about 5 minutes. They do have a "preview site" function, but it is very limited and was not going to work for displaying my content.

So, I had my workaround and my ColdFusion files were showing up just fine. Next, onto the install of ExpressionEngine. No problems. I modified my preferences, uploaded a .htaccess file with some rewrite rules to remove index.php from the URL, and VIOLA! No bubbles, no troubles. Easy URL rewriting working with minimal effort.

After some more clawing at my face while trying to learn mod_rewrite and regex, I finally got my rewrite rules up and running with separate .htaccess files in my root and my EE directory.

I did have a problem a couple of times with the CF server hanging and restarting, but I chatted with support and they are looking into the problem. They offered to move my site to another server if I experience any more problems.

It's refreshing to work with a small team (who reply to requests very quickly) after dealing with GoDaddy nonsense for so long. GoDaddy, for very basic sites, is just fine. But any kind of advanced techniques usually just don't work because of their configuration. They still have the best control panel I've seen on shared hosting. Plesk, which is what HostingNexus uses, is OK, but I miss all of my control on GoDaddy.

The linux version of Plesk is lacking compared to the windows version as well. For example, I cannot add ColdFusion DSNs myself. I need to send them a request. I cannot create additional FTP users, although I got around the problem by using "web users". They are not meant to be FTP accounts, but they do the job. Plesk does not yet support CF9, so HostingNexus has not upgraded yet. I hear when Plesk supports it, they will upgrade, however.

Even with all of that, I'm still very pleased. I canceled my GoDaddy plan this afternoon for my linux hosting, and I'm even paying a bit less per month now. I thought GoDaddy was the cheapest ColdFusion hosting out there, but HostingNexus has them beat by a little bit. I don't have a ton of space (compared to GoDaddy), and I cannot host unlimited domains, but I don't really need either. For this particular hosting plan there will only be one domain and I don't need a ton of space.

HostingNexus also offers one click installs for a ton of open source software including WordPress, Joomla, ZenCart, and many more. And they have plans on linux and windows ranging from $3.95/mo. all the way up to dedicated servers for $349.95. They also offer a reseller package where you can customize Plesk with your logo and configuration.

So, if you are looking for a cheap host on windows or linux, want ColdFusion, and want all of your tags available (yes, even cfexecute, cffile, and cfobject), check out HostingNexus. Cheaper thanGoDaddy and a lot more flexible? Yes please.

The magic of ExpressionEngine

I consider myself to be a web developer, but I'm mostly a front-end developer. Most of the time my job consists of taking .psd files and converting them to XHTML/CSS with jQuery and Flash to fill in the interactive bits. I generally write in PHP of ColdFusion just for basic dynamic elements like includes, form processing, etc. Sometimes I would create a custom CMS depending on the client's needs. My focus is always on UX and keeping it simple for the client while making the designer happy by getting as close to pixel perfect as possible.

More and more clients are asking for the ability to edit their site. Sometimes they ask for blogs, most ask for the ability to update specific sections of pages and add new pages as needed for marketing purposes or whatever they happen to be doing at that time. To solve this problem, I would create sites with custom content management systems. If they wanted a new page, I would provide a basic template and the database would fill in the content by use of a URL variable. The problem was usually SEO (although that's debatable these days) and the lack of URL rewriting ability on hosts like GoDaddy. Instead of a URL like:

http://mydomain.com/articles/the-magic-of-expressionengine

you would get:

http://mydomain.com/articles.cfm?articleID=26

It doesn't really matter to most people. Some folks think it just isn't right and Google doesn't rank you as high. It's hard to say for sure these days (although in my opinion it doesn't matter to Google). But that first URL is much prettier, you have to admit.

Sometimes I would be able to pick the host, but even then URL rewriting wasn't so practical given budget constraints. If they REALLY had no budget I would make templates with Dreamweaver and buy them a Contribute license. Contribute then became the admin section.

I never considered WordPress, Drupal, Joomla, etc. to be viable alternatives because they are so locked down. At least to me. Locked down to me means having limited control over code, limited control over how a publisher could interact with the site, and limited ability on what you could do with it to make your site truly unique. Some people have become very good at wrangling these tools in and making them submit to their whims. However, I feel like I just don't have that kind of time to waste. I was looking for a real CMS that was extremely flexible while allowing me to do basically whatever I wanted. Quickly. That's the reason I use ColdFusion and jQuery. They make my job easier and I can get my work done faster.

I had been aware of ExpressionEngine for some time. Anton Peck has used it for years. I always thought to myself, "Someday I really need to download the EE Core edition and see what the deal is." But I was busy making my custom sites and trying to make clients happy.

This week I finally had some time to download EE and install it. Boy, was I in for a shock. After installing it and playing around for a couple of hours I was totally hooked.

I didn't realize that EE would allow me to completely control my code. I didn't realize that I could lock down the admin section for clients so they only saw what they needed to see. And customize what they saw, at that, all the way down to the nomenclature within the admin. For example, EE uses the term "weblog" for a container for information stored in the database. If I'm building a site that doesn't have a blog, this would probably be confusing to clients. UX, right? So I can go in and change that word to be whatever I want, like "section" or "posts". Not to mention the fact that URL rewriting is enabled by default.

EE is not open source. You must buy a license for a full version (a free Core edition is available, however). This is off-putting to some because WordPress is free and open source. However, WordPress doesn't have all of the built-in modules EE does, not to mention free tech support. Here are some of the modules that can be used with EE:

  • Search
  • Forum
  • Blacklist
  • RSS
  • Wiki
  • Email and Tell a friend
  • Mailing List
  • Comments
  • Membership

And on and on. Save for the Forum module, they all come with a license purchase, which is only $100 for a personal and $250 for commercial.

What that means is that is you want comments on your blog entries, you just call for them using EE syntax. And it's as simple as this:

{exp:comment:entries sort="asc" limit="20"}
{comment}
<p>By {name} on {comment_date format="%Y %m %d"}</p>
{/exp:comment:entries}

That's it. No writing the code for a comments system. It's built-in. You want an RSS feed? Just call for it.

I could go on and on, but the easiest way to figure out why EE is so cool is just to watch some of their videos.http://expressionengine.com/tutorials/

And to look at the features of EE:
http://expressionengine.com/overview/features/

This isn't to say that I'll only use EE from now on. I still subscribe to the "right tool for the job" theory. But a lot of my work can be accomplished using EE and I won't have to write the back-end, write PHP/CFM, or interact with SQL Server or mySQL. This will save me loads of time which I can then use for other things and pass on savings to my clients. Obviously if I'm writing a web application EE will not fit very well, but it has so many features that are generally requested these days that I can see using it quite a bit from now on.

I agree with Aaron Kuzemchak:
http://aaronkuzemchak.com/blog/entry/wordpress-vs.-expressionengine/

It is a disqualification. For WordPress.

ColdFusion queries, bracket notation, & quoted naming

This week I was working on a project where I found myself writing an if statement which compared data in a query to a URL variable and I didn't know what the column name would be. That is, I was looping over a recordset and needed to check if a column, which was defined in a URL variable, had data in it or not. Amazingly, I had never come across this problem before.

First I tried bracket notation:
#rsArticles[URL.language]#

That didn't work. I didn't realize how close I was.

I didn't know what to search for (since bracket notation didn't work, or so I thought), so I started with "coldfusion query dynamic variable" and that led me to Ben Nadel's site:
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm

Except that wasn't exactly what I was searching for. It did lead me to the Evaluate() method. I initially used that for my query access:
#evaluate('rsArticles.'&URL.language)#

That worked. However, Ben made this reader aware of the negative implications of using Evaluate(), so I went about trying to find another way. I'm not sure why Evaluate() has made Ben a bit salty, but I listen when the master speaks.

Finally, I'm not even sure how, I stumbled onto Ray Camden's site and a post called "Queries and Bracket Notation".
http://www.coldfusionjedi.com/index.cfm?mode=entry&entry=395FC479-B91C-4B29-770D3E844309E4F7

That led me to this snippet: #q[col][n]#

Which means, #query[column name][row number]#

So now I realized that I could access my query data with bracket access and I had just missed the [n] value. [n] is the row number, and ColdFusion has a built-in value for getting the current row number, "currentRow".

So my query access became: #rsArticles[URL.language][currentRow]#

That worked, and all was good. But I wondered what if I needed to create a variable on the fly in that bracket notation. That led me back to Ben:
http://www.bennadel.com/blog/152-Dynamic-ColdFusion-Variables-Via-Quoted-Naming.htm

Quoted naming. I had never heard of it. So, say I needed to create a variable name for the column on the fly using my final query access statement. I could do it like this:

 #rsArticles["language_#URL.language#"][currentRow]#

So instead of getting a variable of:
rsArticles.en (where URL.language = en)

I would get:
rsArticles.language_en

This was also touched on by Ray:
http://www.coldfusionjedi.com/index.cfm/2009/11/25/Quick-Tip--Treating-a-ColdFusion-Query-like-a-Structure

So thank you Ben and Ray. You make my life easier by providing such great examples on your blogs. Rock on.

More on iPad and Flash

I thought I was done with the iPad/Flash/Adobe/Apple drama. I tried to let it go. Then I read this article:

http://gawker.com/5474900/what-steve-jobs-said-during-his-wall-street-journal...

Cult of Mac boiled it down to these points:

  • He called Flash a “CPU hog.”
  • A source of “security holes.”
  • A dying technology. Jobs reportedly compared Flash to floppy drives, legacy ports and even the CD. “We don’t spend a lot of energy on old technology,” Jobs reportedly said.
  • The iPad’s battery performance would be degraded from 10 hours to 1.5 hours if it had to spend its CPU cycles decoding Flash,” Jobs supposedly said.
  • Ditching Flash would be “trivial,” Jobs told Journal editors.

It's really becoming annoying, and I feel my Apple fanboy status is in jeopardy. I just don't understand how an entire company can just expect the ENTIRE web to change for their iPhone OS.

However you may feel about Flash, the fact is that there is a lot of content on the web that is in flash that is not video. Even if video is all that had to be replaced on sites, it is going to take an enormous effort to do it.

The fact is that IE cannot support the <video> tag. So it will continue to play Flash video. IE is what MOST of the web uses, like it or not.

And again... Apple wants you to use the H.264 codec for your video (with which I agree), and they want you to use the canvas element for your animations. Both of those things were originated by Apple. Even if browsers agreed on how the <video> tag should be implemented, the canvas element has a LONG way to replicate what Flash can do. Like sound, for example. Something as simple as sound.

I still feel like (average consumer) people who buy an iPad for the cool factor are going to be very disappointed when browsing the web.

I won't get into the fact that every (except for iPhone) new smartphone is Flash 10.1 ready and report no problems.

This is a personal thing with Jobs over Adobe. It has to be. And the fact that Adobe pretty much made Apple what it is today (design folks and editors are notorious for their Mac ownership) makes me very sad. Yes, I realize that iPods and iPhones revolutionized the music and mobile worlds. But before they became a device company, Apple made computers for production professionals. Apple owes a lot to Adobe.

That's not to say that standards should be ignored and the web should stay stagnant. Far from it. But we have to be realistic here, and the fact is that this move (to drop Flash) is going to cost companies (and individual freelancers) money, and generally set the web back a bit. I hope that people will see past the hype and the haters and look at reality.

Again, people don't care what technology is being used to deliver their content. They only care that it works. And with a million different browser/OS combos out there, it is far from "just working."

Think different. Think Adobe. "Wired" is. And their new iPad app (which is a very highly anticipated app) is built with Adobe Air/Flash technology. Exported to a native iPhone OS app, but still built with Flash. If Adobe didn't come along with that new export method, the new Wired app would not be possible without a LOT more time and effort on their part.

http://www.crunchgear.com/2010/02/16/wireds-ipad-app-lookin-good/

I guess Flash is evil, Mr. Jobs. Don't tell Wired! And don't tell Adobe to fix problems that can't be fixed without access to OSX that your team won't give, while you're at it.

Long live Adobe.

Cover bands and web development

I play in a couple of different bands at the moment, both of which play covers. One is a bit heavy on the country side, and the other is a bit heavy on the rock side. Both require a unique approach to really make it happen, but they both have one thing in common: sometimes it isn't what you play but what you don't play.

You see, a lot of musicians get on stage and play all kinds of complex phrasings and chord structures, but in the end the audience, especially if they're dancing, just wants to hear a steady beat and a close-to-the-record representation of the song they are hearing. It doesn't need to be exact...what's the fun in that when you're on stage...but it needs to be close enough for them to be able to sing along. Or at least dance to and know when the chorus or verse is happening.

Being a drummer I used to want to blow out insane 64th note runs and solo over everything...all the time. I just thought the other musicians would see how crazy my chops were and I would be "the guy." But the older I get, I realize that type of attitude has quite the opposite effect.

When I lay down a steady beat, a four on the floor or a standard 2 & 4, the audience dances, the band grooves, and everyone is happy. Sure, I throw in something crazy every now and again...I have to have some escape after playing Brown Eyed Girl for the 65,102,019th time.

That same type of mentality applies to web development. Sometimes it's not about what you can do behind the scenes that matters. Most people going to your site (especially a B2C) don't give a crap if your layout is table-less or not. They don't care if it's Flash or some jQuery plug-in. They just want it to work. They just want to enjoy it. Maybe dance around it a little.

I could go on about UX, the Adobe/Apple debate, and web standards zealots, but this post is about giving the viewer what they need, when they need it, and as easy as possible! As long as your site works, and works well, it doesn't matter if you are using the latest framework or revision of HTML. In fact, depending on which browser your viewers are surfing, you may be doing them a disservice with your latest and greatest bleeding edge code.

Now, I'm all for web standards. I believe in them! Zeldman changed my life years ago when I read "Designing With Web Standards." But the sad fact is we now have a battlefield out there that we have to navigate through as developers. IE6-8, Chrome, Opera, Firefox, Safari, Mobile Safari, and a bunch of other browsers I've never even heard of. If your viewers are coming to your site in IE6, then you need to give them the best experience they can have. Sometimes degrading gracefully or progressive enhancement just isn't the right way to go. Sometimes it needs to be bare bones.

People like flashing things and crap everywhere with no white space. People also appreciate good design. They usually can't articulate what they like about it, other than it "looks nice." It all depends on your audience. They are all different. If you are creating a site for code monkeys, you should be throwing in the latest and greatest because they will be visiting on the latest and greatest. If you are creating a site for the common folk...you had better keep it simple. They have old, slow machines with old, non-standards compliant browsers installed. And they aren't upgrading. Giving them a different experience because you are catering to 5% of your audience just doesn't make sense...no matter what the "experts" say.

Think about your audience, use the best tool for the job, and just make it work. If you can't get a layout right because you think tables are evil and refuse to use them, why not save yourself the headache? Especially if the site won't be updated that often. Use it for that grid (or whatever you are creating) and control the guts with CSS. The standards police won't come for you. Promise. You want a cool animation for your site somewhere? Use Flash. Make sure you have some alternate static content in place for the Flash Nazis and you'll be fine. It doesn't hurt to save hours either. When you send your bill out, or get to your next project faster, your boss/client will have a nice big smile on his face.

In 5 years all of this will still be true...at least the parts about keeping it simple and catering to your audience. Maybe by then we'll see some movement in the browser stats. I have a feeling it is only going to get worse, however.

Let's use what works and makes sense. Don't create new whiz bang stuff at the expense of your viewers. Do it to entice them to upgrade, or do it for the experienced crowd. But keep it simple, and make it easy for them. The last thing people want to do is buy something brand new and see a lego brick where they expect to see content. Even though they may not know it yet. 

Working in an HTML5 world...in 2010

Reading all of the blogs and tweets for the past week I'm actually starting to find the Apple/Adobe posts amusing. Most of the posts are about the death or dominance of Flash, depending on which side of the fence you reside. But I can't wrap my head around how some of these folks are thinking. I can only assume they are under-informed. Here's an example of a conversation that might be taking place in an office near you, very soon.

Developer: As you know, Flash is a closed system and is not open source. I believe we need to strive to be open source in our business, for our clients, and for ourselves. Flash is dead. HTML5 is going to change the way we do business.

Boss: How so?

D: Well, first of all, no more encoding our videos for Flash! We can encode them for the new <video> tag.

B: Is these a cost increase for that?

D: Well, we can't use our .flv encoded files any longer. We'll have to encode for H.264 and OGG.

B: So, we have to encode two videos instead of one, now? And, why aren't we using H.264 for flash player instead of .flv? I just read an article on that.

D: Ummm. Well, .flv is how we've always done it. And the two videos...well, HTML5 is new and...

B: Well, what about browser support? Do these two video formats work in every major browser? I don't want our audience to miss our content.

D: Chrome and Safari support H.264, and Firefox supports OGG. Only the newest versions, of course.

B: What about IE? 70% of our audience is on IE.

D: IE doesn't support the <video> tag. So it should fall back to Flash. All of the browsers that don't support the new technology will fall back to Flash.

B: Let me get this straight. You want me to approve a new workflow that includes encoding two videos instead of one for each video we post to our site. IE uses will see the same thing we are already serving them. And I'm assuming there will need to be a bunch of new code written to support all of these browsers and the fallbacks?

D: Yes. And iPad doesn't allow flash, so we are going to have to do it anyway. And take away rich content within our site and rewrite it.

B: Sigh. What if we left everything the way it is now, at least until browsers catch up a bit? Will all browsers be able to see our content as they do now?

D: Yes, except for iPhone and iPad.

B: And how many people come to our site on iPad or iPhone?

D: Ummm...

B: What about the interactive Flash demo of our product? You're saying we'll need to pull that as well? How can we re-do that without Flash?

D: With the canvas element in HTML5! 

B: How long will it take?

D: Well, there aren't development tools, so we'll have to hand code everything in javascript/css, and there can't be any sound...and it only works in the newest browsers, of course. I'm not really sure how long...

B: I think we'll stick with Flash for now. Let me know when the browsers catch up a bit.

Obviously you can see some problems there when we are talking about real world business costs and not just pie in the sky standards. 

I'm talking about average web users, most of whom are on the default browser that comes with their computer, IE. Not to mention the average user who thinks an iPad is cool (and it is, isn't it?) and wants to play their Farmville on a tablet in their lap. Then they get it home and see a lego brick where their Farmville should be.

I'm all for pushing web standards, but the number of OS/browser combos is ever increasing and it's getting harder and harder to write code that works for everything. Google announced they are dropping support for IE6 finally, so we have a bit more progress on that front. But with browsers now supporting HTML5, it's ANOTHER layer of complexity and testing that has to be done. This cost is being passed on to the businesses coding for the web, and then passed on to the people paying for web content. Shouldn't the cost be going down?

Plug-ins like Flash may not be the answer, but Apple/Adobe/Microsoft/Whoever bickering is not helping things either. Flash filled a void, and HTML5 was proposed to be able to do some of what Flash does without a plug-in. So before you go on that next Flash bashing crusade, think about where we would be without it. Think about what HTML5 is trying to accomplish. Then talk to me about how "evil" flash is.