Words about stuff, and things related to stuff

Remove missing images (and parent elements) using jQuery

My client has an auto dealership site where inventory images are pulled remotely, i.e. 'hotlinked', from the inventory service's website. The client asked me to create a slideshow of inventory images on the home page - no problem using jQuery cycle() plugin - but there's one hangup: some of the images don't exist!  Easy enough to remove the images ( <img onerror="this.style.display = 'none'"> ) , but these images are dynamically linked, and contained in an unordered list. So, even if I remove the errant images with an inline attribute, I still have this empty 'a' and 'li' hanging around.

Using a single line of jQuery code, I whipped up this super-quick solution:

<script type="text/javascript">

// find all missing images
$('#slideshowWrap img').error(function(){

// hide the image, then remove the parent element from the DOM

// uncomment line below to see the script at work
//alert('hidden: ' + $(this).attr('src'));


// end jquery

The parents('a') could become parents('p') or whatever is needed to get rid of the containing element.

Maybe the 'hide()' combined with 'remove()' is redundant.... but I like it.

That 'alert' line, if uncommented, will alert you to the src of each missing image for testing.

jQuery validate() plugin, IE6, simple solution

I have been using the jQuery validate plugin for just about every form I've created in the past year or more. Easy, robust, beautiful stuff by world-class jQuery coder Jörn Zaefferer ( plugin page ) ... if you haven't checked it out yet, please do!

Anyway, tonight I had (yet another) strange thing happen in IE6 - basically, nothing was happening. The form i was working on was able to submit in IE6 as if javascript was disabled - no errors, no message, nothing. As usual, everything was fine in Firefox (firebug) and IE7, and I was stumped as only IE6 can stump me... then, thanks to Google, I found this thread: http://groups.google.com/group/jquery-en/browse_thread/thread/843bc94ffef99250

Apparently there is something in the packed version of the validation file (jquery.validate.pack.js) that IE6 does not like. The solution? Don't use the packed version! Takes up a little more bandwidth but at least it works in all browsers.

Now - how much longer do we have to keep caring about IE6? (In this case, the offending browser is on the client's computer, so I have to play nice as much as possible...)

Firefox: select onChange() when using keyboard - a solution

Working on a CartWeaver site, modifying part of the routine whereby different prices are shown on the page when selecting various options from a dropdown list on the product details page, I noticed that in Firefox, the 'onchange' event of the select list only fires if using a mouse, or when tabbing out of the select box using the keyboard ( select list loses focus).

I guess it's always been this way, I just haven't noticed until now. Fortunately there is a very easy fix - append the 'losing of focus' to the 'onkeyup' event, so that either keyboard or mouse have the same effect, causing the browser to register the 'change'.

Original select list is like this:

<select name="sel" id="sel#i#" onchange=" ( function here )" >

Adding just a bit of code for the onkeyup, like so:

<select name="sel" id="sel#i#" onchange=" ( function here )" onkeyup="this.blur();this.focus();">

we now have a list that loses then regains focus everytime a key is pressed (while it has focus), i.e. using the keyboard to move up or down through the options now triggers a split-second loss and regaining of focus, which is enough to trigger the 'onchange()' in firefox. I love a good easy fix!

Thanks to Sanket Vasa for the tip


CF Gallery Creator & jQuery Slider Gallery !New and Improved!

Still a work in progress, I have fixed a few small things and added better setup notes for the CF Gallery Creator and jQuery Slider Gallery (click for explanation in previous post)

The new code is available as a zip file, attached ** see below **

This package contains

1) a custom ColdFusion image gallery generator, which will create thumbnails and large images of any size you specify from a folder containing your original images, and outputs them to the page in a nice unordered list html markup.

Includes options for multiple subfolders, each one a separate 'gallery' with thumbnail or dropdown navigation.


2) a simply but effective 'slider gallery' built on css and jQuery. Example here:


( Without the jQuery and css, the raw markup from the CF tag alone looks like this


As usual this was built to meet a specific need for a client project and has been tweaked and adjusted along the way.

Please DO try it out, and let me know if/when you use it.
Comments, enhancements and suggestions welcome!

Some alternatives to Adobe NNTP Newsgroups

As many dedicated web developers mourn the passing of the NNTP interface for Adobe's support forums ( formerly nntp://forums.adobe.com ), I'd like to extend a hearty welcome, inviting all web developers, friends and interested cohorts to join myself and a number of other seasoned web professionals in some popular NNTP-friendly alternative hangouts.


In addition to general web developer newsgroups, there are some specialized groups for ColdFusion, javascript (ok, mostly jQuery), all three flavors of CartWeaver (E-commerce) and more.

Every one of the newsgroups listed on the page above is happy to welcome new and interesting contributors, the more the merrier. You may even discover some old friends among the archived threads. 

NOTE: If you are not currently using NNTP to interact with other web-folks online, you've been missing out! I recommend Mozilla Thunderbird, and an account at each one of the places listed. See you there!


In regards to the big switch, the Adobe Dreamweaver support forum says this:

ANNOUNCEMENT: Forums will be unavailable for planned system maintenance
starting at 3pm PST on April 3, 2009. New forums will be online on
Monday April 6, 2009.

( currently April 3, 1:35 Pacific time ... T-minus 90 minutes )

jQuery noSpam email address protector now works with euro domains! (two dots)

Need to show an email address on the web?
You have a few options:

1) create a standard "mailto:" link and enjoy an endless flow of vi@gR&! ads and invitiations for massive funds transfers from far away lands

2) use an email obfuscator!

My favorite email address obfuscator by far is the jQuery noSpam plugin by Mike Branski.
This jQuery plugin turns an obfuscated e-mail address into a human-readable one.

Now supports multiple dots (.) both before and after the at (@) sign!

While the simplicity and smoothness of this little script has always been top-notch, it has just been made even better by allowing the use of euro-style domains, such as " user@domain.co.uk " in addition to standard 'single dot' extensions.

To use this plugin, include jquery.nospam.js and call the nospam() method. No Spam automatically detects if your matched element is a link. If so, it checks the rel attributes for the obfuscated e-mail addresses. For all other elements, it uses the text between the matched tags. 

Examples and further instructions are at http://plugins.jquery.com/project/nospam

jQuery : find empty select boxes (or selects with a specific value)

Another super short jQuery solution to a super long late-night quest on my part.

I have a form with a variable number of select boxes. Before the form can be submitted, I need to verify that there are no selections left unchanged.

The select boxes start out with a default value of ''  (empty quotes). To search for them , i was using all sorts of variations on jquery 'val()', but that is more useful for setting a value than finding a select with a value. After a few various connotations... here's the one that works:

 var valCt = $('select.colorselect[value=""]').size();

This finds all selects with the class of 'colorselect' and the value of '', and returns the size, which in jQuery talk means 'how many'. If I have 3 unchanged select boxes, valCt will equal '3'.

From there it is an easy hop to add a check to the submit action of my form, checking to make sure valCt is 0.

if (!(valCt == 0)) {
return false
} else [ ... submit form here ... ]

Adding Twitter Tweetbacks to BlogCFC - find out if your posts get tweeted!

Thanks very much to Rey Bango for the excellent, easy BlogCFC instructions, and to Dan Zarella for the javascript that makes it go.

The post with full 'how to' is here, on Rey's site:

I just love the cf community... and twitter!

== == ==


The new improved version is here:

Thanks also to Adam Tuttle for the cool sweettweets cfc!



Mobile jQuery Cheat Sheet


made for iPhone/iTouch but works great on my blackberry in Opera mobile. Unlike most of the things I bookmark on my mobile, I can actually see using this one.

here's the actual URL, click this link in your mobile browser:

jQuery in Action 2008 Best Seller (no surprise!)

Manning Publications' jQuery in Action is the book to have if you want to learn jQuery, or if you're a somewhat-jQ-ninja-in-training-ish , and you want to unlock more hidden gems of jQuery wisdom.

I grabbed my copy in advance of the release date last year, and have worn out some of the best pages already.  No surprise to me, Manning just announced that jQuery in Action was their 2008 best seller!

Incidentally , they are running a hefty discount on this and any other titles , for another week or so.

(from the same email announcing the best seller list, in just now... )

Save 31% on any purchase at Manning.com
Enter coupon code ja1331 when you check out
$20 minimum purchase; expires January 13, 2009

Cartweaver Option Selection Fix ( select list javascript )

A small but persistent issue with the default Cartweaver product selection script shows up when a product has more than one set of options. For example, you have skus with a range of colors and a range of sizes.

I finally took a few minutes to create a fix, which was actually quite simple to implement. And in the interest of keeping it non-denominational, I didn't even use jQuery... just plain 'ol javascript that can easily be added to any existing CW site.


...Show Newer

Recent Comments

Importing Events Calendar Data into Mura CMS
Jon said: Hi Michael, Thanks for this post - similarly looking to import data from excel spreadsheet into mur... [More]

New TinyMCE lets you paste as plain text automatically
PRR said: I am using tinyMCE 4.2.3 and configured as suggested in this post but when i try pasting in editor i... [More]

Searching and collecting Mura CMS content by Extended Attribute Value with feed.addParam()
Armando Faes said: After a few hours of head banging - finally thanks to this - Once more THANK YOU! [More]

CF Gallery Creator & jQuery Slider Gallery !New and Improved!
Jan Willis said: Okay, I realized that you are calling my root as the Site - not the wwwroot. So, I moved the JS, CS... [More]

CF Gallery Creator & jQuery Slider Gallery !New and Improved!
Michael Evangelista said: @Jan, it has been a long time (6+ years) so my memory of the details is vague, but I think the image... [More]