Hi
Works fine here.. will focus on first element in first cell on last row in
table
<html>
<head>
<script>
function doIt(){
var e = document.getElementById("myTable");
if(e!=null)
{
var o = e.rows[e.rows.length-1].cells[0].children[0];
if(o!= null) o.focus();
}
}
</script>
</head>
<body onload="doIt()">
<form>
<table id="myTable">
<tr><td><input type="text"></td><td><input type="text"></td></tr>
<tr><td><input type="text"></td><td><input type="text"></td></tr>
<tr><td><input type="text"></td><td><input type="text"></td></tr>
</table>
</form>
</body>
</html>
--
Best Regards
Vidar Petursson
==============================
Microsoft Visual: Scripting MVP 2000-2004
http://www.icysoft.com/ http://www.deus-x.com/ Instant e-commerce
http://www.microsoft.com/technet/scriptcenter/
Playground:
http://213.190.104.211/ ( IE 5.5+ only )
No matter where you go there you are
==============================
"avnrao" <avn@newsgroups.com> wrote in message
news:eIgQamTSEHA.808@tk2msftngp13.phx.gbl...[color=blue]
> Hi,
>
> I am facing a problem with control.focus (javascript). Here is the
> description of the issue.
>
> 1. I have 2 aspx files. on Aspx1 I have button named NewRow. Clicking on
> this, will redirect page to Aspx2 which has a Datagrid. PageLoad of Aspx2
> displays the DataGrid with existing data filled in and shows a new row
> (set of text boxes) in the Footer Item.
> Now, when I set the focus by accessing the first text box in the Footer
> Item, focus is not set. Moreover, I am unable to set the focus to that
> textbox using mouse.
> The textbox is not disabled. I am able to set the focus with mouse when
> just use a tab.
>
> When I remove the .focus code from pageload, thought I focus is not set,
> but I am able to set focus using mouse for the first time.
>
> Basically what I found out is, when I set the focus onto text box, the
> focus has gone to IE menus (File,edit ects..). This is because when
> pageloads, I just typed F, it opened File menu in the IE. I am not sure
> why its behaving this way.
>
> One more information, when I tried a repro of same problem using another
> set of 2 aspx files to check if the issue is coming up there. To my
> surprise, the focus is set properly.
>
> I am setting the focus using the following line.
> document.getElementById('dgCampaign').rows[document.getElementById('dgCampaign').rows.length-1].cells[0].children[0].focus();
>
> when I alert object id, or innerText, I get the proper values.
>
> How to resolve this issue?? Please do reply if you need any more
> information.
>
> thank you,
> Av.
>[/color]