August 9th, 2007
Changing an Internet Explorer input field type via JavaScript
Posted by
Jeremy2 in
Browser Bugs
Ok, this is a problem that has vexed JavaScript programmers for a long time, and frankly most of the solutions for this problem are rather convoluted. At first, I had written a helper function to determine whether or not Internet Explorer was being used, and then I figured out a better way to do things. Here is an example:
var file_input = document.createElement('input');
file_input.type = 'file'; // Works in everything EXCEPT for Internet Exploder
file_input.setAttribute('type', 'file'); // Works for everything I have tried it in so far.
So there. One less nightmare that you have to deal with when coding in JavaScript.