www.webdeveloper.com
Results 1 to 3 of 3

Thread: Order of focus

  1. #1
    Join Date
    Jun 2005
    Posts
    201

    Order of focus

    Hello. A little while back, forum member MrNobody helped me create this Javascript:
    Code:
    function validate() {
        var sections=['terrier', 'sporting', 'mixed', 'poodle', 'salon_free', 'wc', 'creative'];
        var error='Please Enter: \n';
        for(var s=0; s<sections.length; s++) {
            var group=document.getElementById(sections[s]).getElementsByTagName('input');
            var check=false;
            for(var i=0; i<group.length; i++) {
                if(group[i].type=='checkbox' && group[i].checked) {
            	check=true;
                }
                if(group[i].type=='text' && check && group[i].value=='') {
                    error+=group[i].id+'\n';
                    group[i].style.background="#FFFF99";
                }
            }
            group=document.getElementById(sections[s]).getElementsByTagName('select');
            for(i=0; i<group.length; i++) {
                if(check && group[i].selectedIndex < 1) {
                    error+=group[i].id+'\n';
                    group[i].style.background="#FFFF99";
    				group[i].focus();
                }
            }
    		
        }
        if(error!='Please Enter: \n') {
            alert(error);
        }
    
    }
    The script works great, except for one small issue. When the form focuses on the required element, it works from the bottom up. That is, it will focus on the bottom form element and work its way up, rather than work its way down. I would like it to work its way down instead of up. Is there anyway to adjust this behavior? Thanks.

  2. #2
    Join Date
    Feb 2003
    Location
    Michigan, USA
    Posts
    5,774

  3. #3
    Join Date
    Jun 2005
    Posts
    201
    Thanks. It solved the problem of focusing, but now the section order is reversed in the alert box. So, if terrier and sporting are selected, the alert will say sporting, terrier - in that order, but the focus goes correctly with terrier then sporting. Thanks.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles