I have a textbox whose width in pixel should be determined by the number of charaters in it.
The font size for character is fixed.
My logic for this is to setg textbox’s css-width to required width.
requiredWidth = "number of characters" * "fontsize in pixel"
This simple formula Doesn’t work.
Any idea how to convert number of characters into pixels ?
Also is it possible to retrieve a dom element’s size in pixel if the css.width is not set?
Most fonts are not proportionally spaced. “WWWWW” is wider than “iiiii”, therefore counting characters will not work.
You need to put the actual text in a SPAN in the DOM and measure its size.