Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
Discussion GroupsGeneralPHPASPPerlColdFusionFlashHTML, CSS, ScriptsBrowsers

Webmaster Forum / Browsers / Internet Explorer / July 2003



Tip: Looking for answers? Try searching our database.

How to find the nearest input element in html?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
lcl - 29 Jul 2003 10:28 GMT
Hi all experts here,

First, sorry for croll posting.

My customer ask us to implement the key navigating functions: when press the
left row key, the cursor will focus to "previous" control, if press the
right row key, focus to "next" control, but how can I find the "next" or
"previous" control?

Thank you very much.
lichunlin, China
Etan Bukiet - 29 Jul 2003 21:38 GMT
there is actually a very "cute" way to do this in internet explorer using
documment.all;  IE4+
not tested but should work
<script>
function InArray(Arr, Str)
{
 for(var i=0;i<Arr.length;i++) {
  if(Arr[i] == Str) return true;
 }
 return false;
}
var AllTagNameElements = new Array("input", "select", "button"); // stop at
tags with the following tagName values
// add or subtract values from the above array as necessary
window.onload = function()
{
   for(var i=0;i<document.all.length;i++)
   {
       if(InArray(AllTagNameElements,
document.all[i].tagName))document.all[i].onkeydown = doNav;
   }
}
function doNav()
{
   // this func only goes forward, to go backkward change the if condition
to if(i <= 0) return; and chage ++i to --i
   // it goes without saying that you need to check the event.keyCode to
figure out which key was pressed so as
   // to figure out which way to go
   var i = event.srcElement.sourceIndex;
   while(!InArray(AllTagNameElements, document.all[++i].tagName)){if(i >=
document.all.length) return;}
   document.all[i].focus();
}
</script>

hope your script doesn't have to be compatible with NS

etan

> Hi all experts here,
>
[quoted text clipped - 7 lines]
> Thank you very much.
> lichunlin, China
lcl - 30 Jul 2003 01:36 GMT
Thank you very much, I will test it soon.
All our clients use IE, and I saw bill is laughing.

"Etan Bukiet" <ebukiet@comcast.net> дÈëÏûÏ¢ÐÂÎÅ
:e24J$FhVDHA.1512@TK2MSFTNGP11.phx.gbl...
> there is actually a very "cute" way to do this in internet explorer using
[quoted text clipped - 49 lines]
> > Thank you very much.
> > lichunlin, China
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2009 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.