I'm sure every single programmer knows that Internet Explorer has its funny little ways. Getting used to all the funny little ways is somewhat of a mammoth task - and speaking of mammoths, would take the mind the size of a mammoth to memorise them all. Here's another one to put in your collection!
javascript Code:
pForm = document.createElement('form');
pForm.setAttribute('method', 'post');
pForm.setAttribute('action', 'index.php');
pForm.setAttribute('enctype', 'multipart/form-data');
The above code looks so simple. We create a form ready to include into our page. Now, when I was coding
Pture.com I did just that. However, as soon as I tested it in Internet Explorer for my file uploads, the uploads wouldn't work. After some investigation I realised Internet Explorer wasn't setting the enctype attribute on my dynamically created form. After some subsequent research I found out that when creating forms dynamically in Internet Explorer
(both 6 and 7) using Javascript, you need to also set the encoding attribute, for some reason. So although the attribute is called enctype, setting the enctype does nothing. The following code will work:
javascript Code:
pForm = document.createElement('form');
pForm.setAttribute('method', 'post');
pForm.setAttribute('action', 'index.php');
pForm.setAttribute('enctype', 'multipart/form-data');
pForm.setAttribute('encoding', 'multipart/form-data');
Which will save you a good few hours!