Fixing the ‘onClick’ in Dreamweaver

    Alex Walker

    Here’s a Dreamweaver tip from the ‘fishing with dynamite’ department.

    Although it’s not the ideal tool for all tasks, Macromedia Dreamweaver is a very useful tool.

    However it has one particularly nasty little habit that has bugged me for a while now — an infuriating penchant for automatically and forcibly converting my perfectly valid ‘onclick’ attributes to a perfectly invalid ‘onClick’ attributes. As far as I can tell, any time a valid onclick is opened in Dreamweaver, it re-parses the page with uppercase ‘C’s in the onclicks. I’ve searched for settings or preferences to disable it, but to no avail.

    Of course, technically, good ‘unobtrusive JavaScript’ practice would dictate that I shouldn’t be using ‘onclick’ inside my XHTML anyway. No argument. We’re not writing any new ones into the site, but it’s going to take a gradual process to refit some of our older systems. In the meantime, I’m getting ‘real cranky-like’ having to do find & replaces on ‘onClick’ every time I fix a tiny typo in a page — not to mention the disharmony and accusations that were unleashed when we believed we harbored a uppercase evil-doer amongst our ranks.

    My Solution

    I briefly considered picking my way through Dreamweaver’s folder structure looking for the guilty file, but with thousands of files, it looked like taking hours. I settled on a brute strength attack. This method has some risk involved and I make no guarantees or promises, other than it worked for me.

    1) Firstly I made a copy of my ‘Dreamweaver MX 2004/Configuration’ folder and put it somewhere safe — if it all went pear-shaped this was my salvation.

    2) I have used ‘Replace in Files’ from Emurasoft for a while (their little text editor is a tiny gem too). It’s freeware, fast and works, but you may a similar app you prefer. Your call.

    3) I set it to find ‘onClick=’ and replace it with ‘onclick=’. I had no idea what type of file I was targeting, so I set the file type to ‘*.*’ — all files. I also turned on the ‘Match Case‘ option and the ‘Search in subfolders‘ and ‘Match only words‘ options.

    4) Lastly I pointed it at the Dreamweaver ‘configuration’ folder, crossed my fingers, closed my eyes and hit ‘Replace All’.

    One minute later it had finished scanning the nearly 6600 files within that folder, and, as you can see, it found 2676 occurrences of ‘onClick’, which it fixed in nearly 500 files. Gulp. That’s more than I thought…

    However, I’m pleased to report that not only has it definitely fixed the problem, but I have no side-effects, breakages or other problems to report in the meantime.

    Of course, maybe I just haven’t found them yet.

    There is, no doubt, a more elegant solution to this bug, but if it’s an issue for you and you’re feeling brave,..