You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Dave Newton <ne...@pingsite.com> on 2006/03/16 16:39:50 UTC

[OT] Re: Set focus on a table on page load.

Anjishnu Bandyopadhyay wrote:
> Actually, it is a table where rows can be added/deleted.
> So, after, addition/deletion of a row, (on page load) focus is to be set
> to the table.
>   

I'm not convinced you can set focus on a non-input item; that really
wouldn't make any sense.

I believe you'll need to set focus on a user-input control.

Dave



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by Mark Lowe <me...@gmail.com>.
On 3/17/06, Meenakshi Singh <me...@mind-infotech.com> wrote:
> Just for curiosity, I tested this code snippet in IE. However, it does
> nothing.
> Is there anything else that needs to be done.

well you need a table with the id="mytable"..

And you need to set the rowAdded variable, so in the AddRowAction you
could set a request attribute or pass a parameter..

request.setAttribute("rowAdded","true");

and then in jsp

var rowAdded = "${rowAdded}";

this means the focus will only happen if that action has been
executed.. It works in firefox and safari, and i dont like firing up
my pc as is noisey and i feel dirty doing it.. But i think that
offsetTop will be supported..

Mark

>
> Thanks & Regards,
> MS
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Thursday, March 16, 2006 9:29 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: Re: [OT] Re: Set focus on a table on page load.
>
>
>
> On Thu, March 16, 2006 10:39 am, Dave Newton said:
> > Anjishnu Bandyopadhyay wrote:
> >> Actually, it is a table where rows can be added/deleted.
> >> So, after, addition/deletion of a row, (on page load) focus is to be set
> >> to the table.
> >>
> >
> > I'm not convinced you can set focus on a non-input item; that really
> > wouldn't make any sense.
>
> I think you actually can, at least in IE (I was a bit surprised by this).
> Quick test:
>
> <html><head><title></title></head>
> <body onLoad="document.getElementById('myCell').focus();">
> <table>
>   <tr>
>     <td id="myCell" onKeyDown="alert('hello');">My cell</td>
>     <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
>   </tr>
> </table>
> </body></html>
>
> Note that if you load this in IE and just press Return, the onKeyDown
> handler of the first cell fires.  Further, click the second cell and click
> Return.  Again, the handler for *that* cell fires, indicating focus went
> to the cell.
>
> This DOES NOT seem to work in Firefox though, at least when I tried it, so
> it certainly doesn't seem to be cross-browser.  Still, interesting :)
>
> > I believe you'll need to set focus on a user-input control.
> >
> > Dave
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM: fzammetti
> Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Java Web Parts -
> http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [OT] Re: Set focus on a table on page load.

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Nope, I just loaded that up and it worked for me.  Using IE... ah, wait,
technicallly I'm using Maxthon, latest version.  No, wait, just tried it
in IE6 (all latest patches, etc) and it worked there too.  However, I
noticed I got an alert bar about active content, and I had to enable it
first.  Maybe the same thing for you?  Maybe you have IE set to completely
block such content and don't even get the warning bar like I do?  It does
seem to be working for me though in IE6.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

On Fri, March 17, 2006 6:06 am, Meenakshi Singh said:
> Just for curiosity, I tested this code snippet in IE. However, it does
> nothing.
> Is there anything else that needs to be done.
>
> Thanks & Regards,
> MS
>
> -----Original Message-----
> From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
> Sent: Thursday, March 16, 2006 9:29 PM
> To: Struts Users Mailing List
> Cc: Struts Users Mailing List
> Subject: Re: [OT] Re: Set focus on a table on page load.
>
>
>
> On Thu, March 16, 2006 10:39 am, Dave Newton said:
>> Anjishnu Bandyopadhyay wrote:
>>> Actually, it is a table where rows can be added/deleted.
>>> So, after, addition/deletion of a row, (on page load) focus is to be
>>> set
>>> to the table.
>>>
>>
>> I'm not convinced you can set focus on a non-input item; that really
>> wouldn't make any sense.
>
> I think you actually can, at least in IE (I was a bit surprised by this).
> Quick test:
>
> <html><head><title></title></head>
> <body onLoad="document.getElementById('myCell').focus();">
> <table>
>   <tr>
>     <td id="myCell" onKeyDown="alert('hello');">My cell</td>
>     <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
>   </tr>
> </table>
> </body></html>
>
> Note that if you load this in IE and just press Return, the onKeyDown
> handler of the first cell fires.  Further, click the second cell and click
> Return.  Again, the handler for *that* cell fires, indicating focus went
> to the cell.
>
> This DOES NOT seem to work in Firefox though, at least when I tried it, so
> it certainly doesn't seem to be cross-browser.  Still, interesting :)
>
>> I believe you'll need to set focus on a user-input control.
>>
>> Dave
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM: fzammetti
> Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Java Web Parts -
> http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by Dave Newton <ne...@pingsite.com>.
Frank W. Zammetti wrote:
> On Thu, March 16, 2006 10:39 am, Dave Newton said:
>   
>> I'm not convinced you can set focus on a non-input item; that really
>> wouldn't make any sense.
>>     
> I think you actually can, at least in IE (I was a bit surprised by this). 
>   

Ooo, that's spooky... I guess it's a general-purpose element handler,
which makes sense, sorta.

d



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
Should work on IE too... OP, what was the underying goal?  Do you just
want to make sure the added row is on the screen?  If so, I think Mark is
on the right track.

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

On Thu, March 16, 2006 11:18 am, Mark Lowe said:
> If i've understood the problem, rather than trying to focus on the
> table you could create the illusion.. You'd need to get a where the
> table is on the page and perhaps apply some styles to the table. If
> you cant get the position of the table then an anchor will do.. Just
> scroll the window to that.
>
> document.getElementById("mytable").offsetTop
>
> works on firefox and safari.. dont know about ie..
>
> Mark
>
> On 3/16/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>>
>> On Thu, March 16, 2006 10:39 am, Dave Newton said:
>> > Anjishnu Bandyopadhyay wrote:
>> >> Actually, it is a table where rows can be added/deleted.
>> >> So, after, addition/deletion of a row, (on page load) focus is to be
>> set
>> >> to the table.
>> >>
>> >
>> > I'm not convinced you can set focus on a non-input item; that really
>> > wouldn't make any sense.
>>
>> I think you actually can, at least in IE (I was a bit surprised by
>> this).
>> Quick test:
>>
>> <html><head><title></title></head>
>> <body onLoad="document.getElementById('myCell').focus();">
>> <table>
>>   <tr>
>>     <td id="myCell" onKeyDown="alert('hello');">My cell</td>
>>     <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
>>   </tr>
>> </table>
>> </body></html>
>>
>> Note that if you load this in IE and just press Return, the onKeyDown
>> handler of the first cell fires.  Further, click the second cell and
>> click
>> Return.  Again, the handler for *that* cell fires, indicating focus went
>> to the cell.
>>
>> This DOES NOT seem to work in Firefox though, at least when I tried it,
>> so
>> it certainly doesn't seem to be cross-browser.  Still, interesting :)
>>
>> > I believe you'll need to set focus on a user-input control.
>> >
>> > Dave
>>
>> Frank
>>
>> --
>> Frank W. Zammetti
>> Founder and Chief Software Architect
>> Omnytex Technologies
>> http://www.omnytex.com
>> AIM: fzammetti
>> Yahoo: fzammetti
>> MSN: fzammetti@hotmail.com
>> Java Web Parts -
>> http://javawebparts.sourceforge.net
>> Supplying the wheel, so you don't have to reinvent it!
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>> For additional commands, e-mail: user-help@struts.apache.org
>>
>>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by Mark Lowe <me...@gmail.com>.
will this sort of thing do?

window.onload = function() {
  if(rowAdded) {
	var table = document.getElementById("mytable");
       tableFocus(table);
 }
}

function tableFocus(table) {
   	window.scroll(0,table.offsetTop);
	table.style.borderColor = "#f00";
	table.style.borderStyle = "solid";
	table.style.borderWidth = "1px";
       rowAdded = false;
}


On 3/16/06, Mark Lowe <me...@gmail.com> wrote:
> If i've understood the problem, rather than trying to focus on the
> table you could create the illusion.. You'd need to get a where the
> table is on the page and perhaps apply some styles to the table. If
> you cant get the position of the table then an anchor will do.. Just
> scroll the window to that.
>
> document.getElementById("mytable").offsetTop
>
> works on firefox and safari.. dont know about ie..
>
> Mark
>
> On 3/16/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
> >
> > On Thu, March 16, 2006 10:39 am, Dave Newton said:
> > > Anjishnu Bandyopadhyay wrote:
> > >> Actually, it is a table where rows can be added/deleted.
> > >> So, after, addition/deletion of a row, (on page load) focus is to be set
> > >> to the table.
> > >>
> > >
> > > I'm not convinced you can set focus on a non-input item; that really
> > > wouldn't make any sense.
> >
> > I think you actually can, at least in IE (I was a bit surprised by this).
> > Quick test:
> >
> > <html><head><title></title></head>
> > <body onLoad="document.getElementById('myCell').focus();">
> > <table>
> >   <tr>
> >     <td id="myCell" onKeyDown="alert('hello');">My cell</td>
> >     <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
> >   </tr>
> > </table>
> > </body></html>
> >
> > Note that if you load this in IE and just press Return, the onKeyDown
> > handler of the first cell fires.  Further, click the second cell and click
> > Return.  Again, the handler for *that* cell fires, indicating focus went
> > to the cell.
> >
> > This DOES NOT seem to work in Firefox though, at least when I tried it, so
> > it certainly doesn't seem to be cross-browser.  Still, interesting :)
> >
> > > I believe you'll need to set focus on a user-input control.
> > >
> > > Dave
> >
> > Frank
> >
> > --
> > Frank W. Zammetti
> > Founder and Chief Software Architect
> > Omnytex Technologies
> > http://www.omnytex.com
> > AIM: fzammetti
> > Yahoo: fzammetti
> > MSN: fzammetti@hotmail.com
> > Java Web Parts -
> > http://javawebparts.sourceforge.net
> > Supplying the wheel, so you don't have to reinvent it!
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> > For additional commands, e-mail: user-help@struts.apache.org
> >
> >
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by Mark Lowe <me...@gmail.com>.
If i've understood the problem, rather than trying to focus on the
table you could create the illusion.. You'd need to get a where the
table is on the page and perhaps apply some styles to the table. If
you cant get the position of the table then an anchor will do.. Just
scroll the window to that.

document.getElementById("mytable").offsetTop

works on firefox and safari.. dont know about ie..

Mark

On 3/16/06, Frank W. Zammetti <fz...@omnytex.com> wrote:
>
> On Thu, March 16, 2006 10:39 am, Dave Newton said:
> > Anjishnu Bandyopadhyay wrote:
> >> Actually, it is a table where rows can be added/deleted.
> >> So, after, addition/deletion of a row, (on page load) focus is to be set
> >> to the table.
> >>
> >
> > I'm not convinced you can set focus on a non-input item; that really
> > wouldn't make any sense.
>
> I think you actually can, at least in IE (I was a bit surprised by this).
> Quick test:
>
> <html><head><title></title></head>
> <body onLoad="document.getElementById('myCell').focus();">
> <table>
>   <tr>
>     <td id="myCell" onKeyDown="alert('hello');">My cell</td>
>     <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
>   </tr>
> </table>
> </body></html>
>
> Note that if you load this in IE and just press Return, the onKeyDown
> handler of the first cell fires.  Further, click the second cell and click
> Return.  Again, the handler for *that* cell fires, indicating focus went
> to the cell.
>
> This DOES NOT seem to work in Firefox though, at least when I tried it, so
> it certainly doesn't seem to be cross-browser.  Still, interesting :)
>
> > I believe you'll need to set focus on a user-input control.
> >
> > Dave
>
> Frank
>
> --
> Frank W. Zammetti
> Founder and Chief Software Architect
> Omnytex Technologies
> http://www.omnytex.com
> AIM: fzammetti
> Yahoo: fzammetti
> MSN: fzammetti@hotmail.com
> Java Web Parts -
> http://javawebparts.sourceforge.net
> Supplying the wheel, so you don't have to reinvent it!
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
> For additional commands, e-mail: user-help@struts.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


RE: [OT] Re: Set focus on a table on page load.

Posted by Meenakshi Singh <me...@mind-infotech.com>.
Just for curiosity, I tested this code snippet in IE. However, it does
nothing.
Is there anything else that needs to be done.

Thanks & Regards,
MS

-----Original Message-----
From: Frank W. Zammetti [mailto:fzlists@omnytex.com]
Sent: Thursday, March 16, 2006 9:29 PM
To: Struts Users Mailing List
Cc: Struts Users Mailing List
Subject: Re: [OT] Re: Set focus on a table on page load.



On Thu, March 16, 2006 10:39 am, Dave Newton said:
> Anjishnu Bandyopadhyay wrote:
>> Actually, it is a table where rows can be added/deleted.
>> So, after, addition/deletion of a row, (on page load) focus is to be set
>> to the table.
>>
>
> I'm not convinced you can set focus on a non-input item; that really
> wouldn't make any sense.

I think you actually can, at least in IE (I was a bit surprised by this).
Quick test:

<html><head><title></title></head>
<body onLoad="document.getElementById('myCell').focus();">
<table>
  <tr>
    <td id="myCell" onKeyDown="alert('hello');">My cell</td>
    <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
  </tr>
</table>
</body></html>

Note that if you load this in IE and just press Return, the onKeyDown
handler of the first cell fires.  Further, click the second cell and click
Return.  Again, the handler for *that* cell fires, indicating focus went
to the cell.

This DOES NOT seem to work in Firefox though, at least when I tried it, so
it certainly doesn't seem to be cross-browser.  Still, interesting :)

> I believe you'll need to set focus on a user-input control.
>
> Dave

Frank

--
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org



---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by "Frank W. Zammetti" <fz...@omnytex.com>.
On Thu, March 16, 2006 10:39 am, Dave Newton said:
> Anjishnu Bandyopadhyay wrote:
>> Actually, it is a table where rows can be added/deleted.
>> So, after, addition/deletion of a row, (on page load) focus is to be set
>> to the table.
>>
>
> I'm not convinced you can set focus on a non-input item; that really
> wouldn't make any sense.

I think you actually can, at least in IE (I was a bit surprised by this). 
Quick test:

<html><head><title></title></head>
<body onLoad="document.getElementById('myCell').focus();">
<table>
  <tr>
    <td id="myCell" onKeyDown="alert('hello');">My cell</td>
    <td id="myCell2" onKeyDown="alert('hello2');">My cell2</td>
  </tr>
</table>
</body></html>

Note that if you load this in IE and just press Return, the onKeyDown
handler of the first cell fires.  Further, click the second cell and click
Return.  Again, the handler for *that* cell fires, indicating focus went
to the cell.

This DOES NOT seem to work in Firefox though, at least when I tried it, so
it certainly doesn't seem to be cross-browser.  Still, interesting :)

> I believe you'll need to set focus on a user-input control.
>
> Dave

Frank

-- 
Frank W. Zammetti
Founder and Chief Software Architect
Omnytex Technologies
http://www.omnytex.com
AIM: fzammetti
Yahoo: fzammetti
MSN: fzammetti@hotmail.com
Java Web Parts -
http://javawebparts.sourceforge.net
Supplying the wheel, so you don't have to reinvent it!

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org


Re: [OT] Re: Set focus on a table on page load.

Posted by Emmanouil Batsis <Em...@eurodyn.com>.
Dave Newton wrote:

>I'm not convinced you can set focus on a non-input item; that really
>wouldn't make any sense.
>
>  
>
+1

I'd try using a fragment identifier (pointing to <a name....) either 
from the link that leads to the page or via JS on load (the first way is 
better).

hth,

Manos

---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org