|
-
Apr 15th, 2009, 06:55 AM
#1
[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?
-
Apr 15th, 2009, 07:35 AM
#2
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.
-
Apr 15th, 2009, 07:39 AM
#3
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.
-
Apr 15th, 2009, 08:09 PM
#4
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.
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Apr 16th, 2009, 02:16 AM
#5
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.
-
Apr 16th, 2009, 06:36 AM
#6
Re: [JAVASCRIPT] Focus on Control Problem
Maybe you are suppose to put enable/disable value inside the brackets?
HTML Code:
e.focus(True);
when you quote a post could you please do it via the "Reply With Quote" button or if it multiple post click the "''+" button then "Reply With Quote" button.
If this thread is finished with please mark it "Resolved" by selecting "Mark thread resolved" from the "Thread tools" drop-down menu.
https://get.cryptobrowser.site/30/4111672
-
Apr 16th, 2009, 06:59 AM
#7
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.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|