Well, what I'm trying to: auto-format an input type as user writes down
Suppose a form input, type text, which will cotain numbers, and I want to format them with the correct number format; i.e.: (EU format) "2222,222" --> "2.222,222" // (US format) "2222.222" --> "2,222.222"
Ok.
So I'm developing my own jQuery plugin "numberFormat" which registers for any object the listeners for keypress, change and blur events.
Right now, I can format the number as the user is writting down or changes the focus to another element.
The main issue cames whenever I try to modify a text that is already formatted.
Example:
1. First I type the number: "2222", in EU format will be "2.222"
2. Then I change focus from input to another element of the web, and the text of the input get its format.
3. Next, I modify the text, tipping down an extra '3' at the beginning, so the number should result as "32.222"
And the question is:
How I know in which position of the current value array is the new char going to be?
- I didn't know it was imposible, so far I wouldn't had achieved it. -
I have developed a "fake" <SELECT>, because of project requirements.
My code is easy to understand, I have an <INPUT> and a <DIV> with an inner <UL>.
Whenever I click on the <INPUT>, the <DIV> is showed (hidden by default by CSS).
Whenever I pick one <LI> from the <UL>, the <DIV> turns hidden, or if I change manually the <INPUT> value.
But the problem cames when I click somewhere else of the page without picking one of the <LI>.
I had tried with myInput.blur(function(){ //something here }); but it cames to me that this is launched whenever <INPUT> loose the focus, so it doesn't matter if the user clicks over one <LI> or somewhere else.
Is there any way to know If the user is clicking over the displayed "fake" <SELECT>?
This works fine one the data is loaded, or the window is resized manually, but it doesn't works when I click on the maximize or minimize browser buttons.