In Javascript: (This is in the calculateBMI function that I have written)
document.form1.WtCurrLb.value = 123;
If I set the value like in that last line of code, then click in the textbox, the cursor automatically goes after the 3, then half a second later jumps to before the 1. It is definitely that line of code that is causing that behavior, which makes working with the page a huge PITA and is causing data errors.
Any ideas why this is happening? FWIW, this is happening in IE.
as best I can see from the meaning of “onBlur” what you are asking it to do is…
'when the WtCurrLb field loses focus, set its value to 123"
When you click on the textbox (by which I assume you mean the WtCurrLb textbox) the onBlur event shouldn’t even be triggered. So something else is going on.
That’s half correct. I’m actually calling the function from 4 different textboxes. So I also have a textbox called WtCurrKg. If I’m in WtCurrKg then click on WtCurrLb, then the OnBlur from WtCurrKg is invoked, causing this behavior. If I get there from some other input without the OnBlur, the behavior doesn’t happen.
So if you have three boxes, WtCurrKg - WtCurrLb - Height, and you have WtCurrKg set so that onBlur/losing focus, it sets WtCurrLb to the equivalent in lbs, what you want to happen is that if you type a weight into WtCurrKg, then click Height, a new value appears in WtCurrLb (say in this case they put 56 in WtCurrKg so the value is 123 that should go into WtCurrLb). So what happens is that instead of the focus going to Height as the click directed, the focus jumps to WtCurrLb to after the 3, then a moment later to before the 1 ?
In that scenario, focus would go to Height, as expected. But the cursor goes to the end of height, then snaps to the beginning. So if the height is 72, it would look like this: 72| then this: |72. So focus goes to the right box, it’s just the cursor that’s acting funny.
And all 3 boxes (actually, 4) have the same OnBlur event, which just goes to a function with a decision tree.
This is a bug in IE8. You should be able to add some JS to set the location of the cursor, but with the method you are using I think it will be troublesome. What is your end goal and what requirements can you not budge on? Maybe we can help you come up with a more effective cross-browser compatible approach.
Thanks for letting me know it’s a bug. Knowing this, I was able to find a few references to it on the web.
Here’s the scope of the issue:
We have two nearly identical forms where a patient’s health issues can be listed. One is external, for patients to fill out at home, the other is internal for physicians to fill out. The internal one must be used with IE.
This particular section has 5 textboxes and a button. The textboxes are:
Weight in pounds
Weight in kilograms
Height in inches
Height in centimeters
BMI
BMI is read only. When any of the first four is exited, the others will be calculated, if possible. The button doesn’t actually do anything but entice the user to click on something else, triggering an OnBlur.
I suppose I could get rid of the OnBlur and have the button call the code. The bahavior would still exist but hopefully the user wouldn’t have any reason to go back. And if the button is not clicked, the submit button could invoke the code. (All that’s saved is the metric values.)
Sorry, but I’m missing why this is a problem. It’s just an out of place cursor in a small read-only field, or is there something else? Anyway, problems like this abound in JS, choose your work-around and move on, you’ll have plenty of other problems to resolve.
ETA: Ok, now I see this was not a read-only field that was the problem. Hmm. I may have run into something like this before. I’ll try to recollect and get back to this.
It’s a problem because there are a lot of typos, and I see the pained expression on users’ faces when they have to go back and type it again. I want to make using this form as painless as possible. And some typos get through. Last week I found a record for a 40 foot tall woman. (With a BMI of something like 1.8.)
Very good solution geneb. I hate browser programming because of this kind of weirdness, but I think I’ll add the onFocus=“this.select()” to every input component when I have to do it.