jQuery Library Logo © John Resig.

jQuery Library Logo © John Resig.

Ok, so I was writing some validation code to stop empty submition of a form in a quiz/servey I was building for Natural Tys. The easiest was to do client side validation is by using the excellent Javascript frameworks that are available. My personal favourite is jQuery which has a excellent validation plugin available, you can get it over at bassistance.de. The only problem was that it didn’t seem to work in Internet Explorer 6, dispite the fact that the demos provided at bassistance.de worked great. I kept getting a ‘method and/or object does not exist’ error, or something similar. You may also receive some syntax errors such as ‘unexpected :’. Anyway if you’re getting this & you’re also ready to bang your head against the wall, here is how to fix it.

The problem is all to do with the fact most HTML files are geneated with charset=UTF-8 in the meta tag. If you make your own HTML files then you may not have this problem, I don’t know because I use Dreamweaver which does all the meta tag stuff for you. Anyway, if your HTML file is UTF-8 then all you need to do is change your script tag. You should have a script tag that looks something like this, inbetween your head tags:

<script src="jquery.validator.pack.js" type="text/javascript"></script>

All you need to do is replace it with this:

<script src="jquery.validator.pack.js" type="text/javascript" charset="ISO-8859-1" ></script>

That should fix it. The problem is simple. FF, IE7 and most other browsers can automatically detect and switch character sets as they need to, but Internet Explorer 6 being as useless as it is can’t. That’s why you need to hold it’s hand and actually tell it what character set the file is encoded in. Why is the file in ISO-8859-1 encoding? I don’t know…