473,735 Members | 1,923 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Focus on text field in TD

VA
t=document.getE lementById('myt able')
is a HTML table with some input fields in its cells

Why doesnt

t.getElementsBy TagName('tr')[1].firstChild.foc us;

put the focus on that text field? It doesnt give any errors, the focus
just doesnt change.

What am I doing wrong? Thanks

Nov 11 '05 #1
3 6896
VA said the following on 11/10/2005 10:09 PM:
t=document.getE lementById('myt able')
is a HTML table with some input fields in its cells

Why doesnt

t.getElementsBy TagName('tr')[1].firstChild.foc us;
put the focus on that text field? It doesnt give any errors, the focus
just doesnt change.

What am I doing wrong? Thanks


Maybe you forgot the () on your focus call (thats #1 guess).
Maybe you have extra whitespace in your code.

Show the HTML and JS code.

--
Randy
comp.lang.javas cript FAQ - http://jibbering.com/faq & newsgroup weekly
Javascript Best Practices - http://www.JavascriptToolbox.com/bestpractices/
Nov 11 '05 #2
VA wrote:
t=document.getE lementById('myt able')
is a HTML table with some input fields in its cells
By 'input fields' do you mean input elements?

Why doesnt

t.getElementsBy TagName('tr')[1].firstChild.foc us;
You need to show the related HTML. If you have:

<table id="mytable">
<tr>
<td>...</td>
</tr>
<tr>
<td><input ...></td>
</tr>
</table>

In Geko browsers (and likely some others too) your reference will be to
a text node that will seem to be immediately after the second <tr> tag.
In IE, your reference will be to the TD element, not the input element.
If the HTML for the second TR element is:

<tr><td><inpu t ...></td></tr>
Then in Geko browsers your reference will also be to the TD element.


put the focus on that text field? It doesnt give any errors, the focus
just doesnt change.
The W3C DOM 2 specification does not define a focus method for Interface
HTMLTableCellEl ement, so at least some browsers will not implement it.

What am I doing wrong? Thanks


For those browsers that do have a focus method for table cells:

t.getElementsBy TagName('tr')[1].firstChild.foc us();
Should do. If you want to reduce error messages in browsers that don't
support focus for cells, then:

var c = t.getElementsBy TagName('tr')[1].firstChild;
if ( c && c.focus ) c.focus();
will do better.

If you are after the text input (which does have a focus() method
defined in the specification) that is inside the cell, you should change
your reference to it and not the cell and feature test anyway:

if (document.getEl ementsByTagName ){
var c = t.getElementsBy TagName('tr')[1].firstChild;
var x = (c && c.getElementsBy TagName('input' )[0]);
if (x && x.focus) x.focus();
}

--
Rob
Nov 11 '05 #3
VA
Thanks, Rob. I was missing the

var x = (c && c.getElementsBy TagName('input' )[0]);

part. The TD had some other stuff in it that I didnt care about, I
wanted just the INPUT element in it.

Thanks!

Nov 11 '05 #4

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

Similar topics

5
28143
by: 'bonehead | last post by:
Greetings, I'm still something of a newbie to html/php/mysql. I have a php/html form with several fields of type "input". If the user enters improper data in a particular field and clicks the Submit button, the php script has to trap it and return a javascript error message box with an OK button. That part I've already got down. But, you know how in Visual Basic you can set the focus on the offending
2
14299
by: fish | last post by:
Hi, I have an HTML page with a FORM and some input fields. On the fields I wish to do validation as the punters change the field values. If they get it wrong, then I tell them and then wish to put the focus back to the offending field. ( It works if a use an 'onblur' event but not an 'onchange' )
3
5373
by: Dan | last post by:
This function validates a price field on my form. It fires with onchange. If the validation fails, I want the focus to return to the same field so that the user can correct it. The way it is working now, the focus moves to whichever field is clicked upon exiting this field. The behavior is the same in ie,ns and opera. This is probably simple, but I don't understand why this doesn't work Any ideas would be much appreciated. Thanks. ...
10
6715
by: CES | last post by:
All, I'm having a problem returning focus back to an input field in Netscape. The code works in IE and Opera but not in netscape6+. Basically I have a function that is called upon exiting a form field, if the
3
2624
by: Dai Ba Wong | last post by:
Hi: Currently I am having a problem with my webpage. My page consist of two frames, one consist of input text field and the other contains link for different pop-up windows. The problem follows: 1. At the beginning, focus is placed on an input text field of the first frame (so there's a blinking cursor on such field). 2. Then users click on a link of the second frame (thus focus is set
1
1830
by: Jens Körte | last post by:
Hi NG! I encountered some strange behaviour when using focus() I use a form with several input-fields. A user can enter stuff. After entering I want to check the value, i.e. that a number is only a number etc. I therefore started editing a Javascript. For test purposes it only popup a message and sets the focus. In fact this is what I want to do, but the scipt isn't it doing right.
3
8315
by: Steve Yerkes | last post by:
There seems to be way too much confusion over how to set focus on the a field using a field validator. I looked all over the web and found people trying to do this, but not getting anywhere. There are a couple of people selling components... but that is not really an option for me... So, I took the plunge and modified the "WebUIValidation.js" file to make it happen... After tracing through file, I figure it out. It was actually pretty...
4
2581
by: bienwell | last post by:
Hi, I have a problem and really need your help. In my web page ASPX, I have some text fields to accept data from users. I did form validation like this : <td class="dataTD" style="HEIGHT: 30px" width="100"> <asp:TextBox id="txtFUEL_ISSUED1" style="Z-INDEX: 100; POSITION: absolute" runat="server" Width="107px" BorderColor="Transparent" autoPostback="true"
4
13449
by: planb | last post by:
Hi, I'd like to have a rollover like effect when a input field has the focus, any idea of how to do this with just CSS (easy enough with javascript)? What I'm thinking of is having a tips box show up next to the input field, but only when the field actually has focus. I was thinking if there's any way to make the focus apply to a
0
8786
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
9466
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9330
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9255
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6748
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6050
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3278
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 we have to send another system
2
2741
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2191
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.