[JAVASCRIPT] Focus on Control Problem
Hi,
I'm using this code:
HTML Code:
var e=$get('myTextBox');
e.value = result;
e.focus();
(yes, that's ajax mixed)
This works ok in normal cases.
But the focus on control works only once, the first time this code executes.
When this code is executed again, I can see that the textbox value has changes (which means it is working), but the focus is not set on the textbox.
Anyone.. any idea why?
Re: [JAVASCRIPT] Focus on Control Problem
Interestingly if I add e.select() to it, it sets the focus on the control as well as selects the text.
Code:
var e=$get('myTextBox');
e.value = result;
e.focus();
e.select();
But I don't want it selected. I only want the focus set on that textbox.
Re: [JAVASCRIPT] Focus on Control Problem
ok... I figured out a workaround by experimenting. If I call e.focus() twice, the focus is set there. Though I have no idea why.
Code:
var e=$get('myTextBox');
e.value = result;
e.focus();
e.focus();
Anyways I'll leave the thread open for now for anyone who knows why this is happening, since what I'm doing is just a workaround and far from understanding.
Re: [JAVASCRIPT] Focus on Control Problem
Try:
HTML Code:
e.select = false;
I haven't used ajax before so I'm not sure if that code is correct.
Re: [JAVASCRIPT] Focus on Control Problem
That's pure javascript. $get is just a shortcut function for document.GetElementById in ajax. Since I was dealing with partial postbacks, that function was available to me and I used it. And it is working fine too, since I can see the textbox being updated and any other javascript I may insert there; like alert(something) etc.
The problem is why do I need to call the control.focus() method twice in quick succession to set the focus?? From what I know one call is the same as 100 calls, there should be nothing special going on there with the focus() method.
BTW, I tried that e.select = false; but it doesn't work.
Re: [JAVASCRIPT] Focus on Control Problem
Maybe you are suppose to put enable/disable value inside the brackets?
HTML Code:
e.focus(True);
Re: [JAVASCRIPT] Focus on Control Problem
Nope... that doesn't work either.
e.focus() is a valid call and even works for the first time the function is executed. Problems happen from 2nd call onwards.