Tuesday, August 05, 2008

Styling form file input

Due to certain security considerations, it is very difficult to change the style of file input.
Here is a good post on how to do it.

Following is quoted from above article:
  1. Take a normal < type="file">
  2. To this same parent element, add a normal <> and an image, which have the correct styles. Position these elements absolutely, so that they occupy the same place as the < type="file">.
  3. Set the z-index of the < type="file"> to 2 so that it lies on top of the styled input/image.
  4. Finally, set the opacity of the < type="file"> to 0. The < type="file"> now becomes effectively invisible, and the styles input/image shines through, but you can still click on the "Browse" button. If the button is positioned on top of the image, the user appears to click on the image and gets the normal file selection window.
    (Note that you can't use visibility: hidden, because a truly invisible element is unclickable, too, and we need the < type="file"> to remain clickable)
  5. When the user has selected a file, the visible, fake input field should show the correct path to this file, as a normal < type="file"> would. It's simply a matter of copying the new value of the < type="file"> to the fake input field, but we need JavaScript to do this.

Linking with static runtime libraries with MFC

In Visual C++, due to some conflicts between libcmt.lib and nafxcw.lib, you need to
make following changes in Linker->Input

Additional Dependencies: nafxcw.lib libcmt.lib
Ignore specific libraries: libcmt.lib nafxcw.lib

Wednesday, May 28, 2008

Using C99 support in Intel Compiler

C99 only works for C. Not C++. So the code must be compiled as C code not C++ code.

Thursday, April 24, 2008

javascript variable scope

The scope of a variable is the current function or, for variables declared outside a function, the current application.
Aassigning a value to an undeclared variable implicitly declares it as a global variable.

Each function is associated with its closure chain
A variable is undefined if cannot be found in the current closure chain,
and the access attemp will generate error.

The global function 'eval' uses current closure chain to evaluate the string.
If a function is still accessible, its function closure chain is still in memory.

Tuesday, April 22, 2008

Image flicker in IE6

This is due to IE 6 keeps check for the background image specified in css property everty time the element is moved over. Note that IE 5 or IE 7 do not have this problem.

A good post about this problem is at http://www.mister-pixel.com/

The solution is to add following javascript code inside the HEAD of the page:
try {
document.execCommand("BackgroundImageCache", false, true);
} catch(err) {}

This fix works only with Internet Explorer 6, Service Pack 1 or newer.
Also, the fix does not apply if you change the background image on :hover. It only prevents the flicker of the same background image, when changing other rules inside the :hover state. But you can still change the background position.