473,472 Members | 1,702 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Focus Not Being Recognized

I have a simple input element that is created dynamically using
javascript as follows:

myINPUT = document.createElement("INPUT");
myINPUT.type="text";
myINPUT.id = myINPUT.name = "amt"
myINPUT.value = "0";
myINPUT.className = "textNumber";
myINPUT.maxLength = "8";
myINPUT.size = "8";
myTD.appendChild(myINPUT);

After this gets added I'd like it to get the focus.

I use:

document.myform.elements["amt"].focus();

The message I get is that the field is null or does not exist.

Is this not getting inserted into the IE forms collection properly?

Is there a workaround to getting this newly created input element the
focus?

Mike

Jul 23 '05 #1
5 1515
<snip>
The message I get is that the field is null or does not exist.
<snip>

I told a story. I had another error in the javascript. Once I fixed
that error the message went away.

It still is not getting the focus though.

Jul 23 '05 #2
if in my javascript I put an alert right after the focus statement,
then it works, like:

document.myform.elements["amt"*].focus();
alert("amt");

Mike

Jul 23 '05 #3
More information. This javascript posted above is executed when the
value in another textbox changes.

When I input a value and "click outside the textbox with the mouse" to
the document area, then I "do not" get focus.

When I input a value and the hit the "tab" key, then I "do" get focus.

Does this make sense to any one?

Jul 23 '05 #4
mike wrote:
I have a simple input element that is created dynamically using
javascript as follows:

myINPUT = document.createElement("INPUT");
myINPUT.type="text";
myINPUT.id = myINPUT.name = "amt"
myINPUT.value = "0";
myINPUT.className = "textNumber";
myINPUT.maxLength = "8";
myINPUT.size = "8";
myTD.appendChild(myINPUT);

After this gets added I'd like it to get the focus.

I use:

document.myform.elements["amt"].focus();

The message I get is that the field is null or does not exist.

Is this not getting inserted into the IE forms collection properly?

Is there a workaround to getting this newly created input element the
focus?


Try this:

myINPUT = document.createElement("INPUT");
myINPUT.type="text";
myINPUT.id = myINPUT.name = "amt"
myINPUT.value = "0";
myINPUT.className = "textNumber";
myINPUT.maxLength = "8";
myINPUT.size = "8";
myTD.appendChild(myINPUT);
document.myform.amt = myINPUT;
document.myform.elements.amt = myINPUT;
document.myform.elements["amt"].focus();

Internet Explorer doesn't add the usual references -
document.form_name.element_name and
document.form_name.elements.element_name - to form controls appended
dynamically.

Jul 23 '05 #5
mike wrote:
More information. This javascript posted above is executed when the
value in another textbox changes.

When I input a value and "click outside the textbox with the mouse" to
the document area, then I "do not" get focus.

When I input a value and the hit the "tab" key, then I "do" get focus.

Does this make sense to any one?


A focus/blur/timing issue of sorts.

..........
..........
myINPUT.size = "8";
myTD.appendChild(myINPUT);
setTimeout('var el;if(el=document.myform.elements.amt)el.focus()', 50);

Jul 23 '05 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: melanieab | last post by:
Hi again, With much help, I've finally gotten the Tab key to be recognized when a textbox is in focus, but now I'm having trouble with the up/down keys when they're focused on a custom button (on...
10
by: dba123 | last post by:
Why am I getting this error for Budget? Error: An exception of type 'System.FormatException' occurred in mscorlib.dll but was not handled in user code Additional information: String was not...
0
by: saltima | last post by:
Hi all, I'm trying to automate my web browser testing by using Pamie and Python. Everything is going great except for when a new window opens up. (on the previous page, I click next, and a...
2
by: hitide | last post by:
I made an interactive webpage, wich should be controlled with keystrokes via javascript. My problem is, that in IE6 (witch latest update) and IE 7 it does only work, when I place a mouseclick into...
3
by: atn2002 | last post by:
I'm trying to create a control which when the mouse button gets pressed on one div an absolute positioned div pops up in place of the cursor. From there the cursor should interact with the dialog...
2
by: douha | last post by:
Hi all, I am using IE version 6 and I am moding the jscript for an existing page in an application. I am setting the page up so that whenever a function key or any combination of keys...
2
by: ruthiefy | last post by:
Hi, I need a few sql queries results so I created a new class with has a few functions that load the data. After executing ExecuteReader, I need to load the data to the dropdownlist control....
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.