SitePoint Sponsor

User Tag List

Results 1 to 3 of 3

Hybrid View

  1. #1
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Using arrows to change input focus

    I had a request recently for a script which moves from input to input using the up and down arrows.
    It should skip buttons and password fields, and it should loop from the first element to the last.

    What i produced may be of interest to people here:
    Code:
    var i = document.getElementsByTagName('INPUT');
    var ia = new Array;
    var c=0;
    for (o=0;o<i.length;o++){
            if (i[o].type=='text'){
                    i[o].idref=c;
                    ia[c++]=i[o];
                    }
            }
    il = ia.length-1;
    function Khandler(){
            e=event;
            k=e.keyCode;
            s=e.srcElement
            if (k==40||k==38){
                    if (s.tagName=='INPUT' && s.type=='text'){
                            var m = (k==40)?+1:-1;
                            m=(k==38&&s.idref==0)?+(il):((k==40&&s.idref==(il))?-(il):m);
                            alert('the giraffe\'s can\'t get me now -> '+s.idref+' | '+m+' gives: '+ia[s.idref+m].name);
                            ia[s.idref+m].focus();
                            }
                    }
    As you can see - this uses an object reference array to handle the mechanism of referencing the desired objects.

    An example of the use of it:
    http://develop.thermeoneurope.com/scroll.html

    Well - that's all.
    Questions / Comments / Suggestions welcome.

    ( the script was for ie5.5+ envs - btw )

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---

  2. #2
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Interesting. Although I think I'd loop through the form's elements collection and snag all the INPUT type=text, SELECTs and TEXTAREAs for ia
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  3. #3
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yeah - me too - but that's just what they wanted.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •