[Javascript] (no subject)

Roger Roelofs rer at datacompusa.com
Thu Jan 13 14:29:51 CST 2005


Dear list.

I'm working on a project for large amounts of data entry via the web.  
I have a routine (pasted below) that examines the content of the 
current entry field and automatically goes to the next field when the 
correct number of characters have been typed.  The function works well 
except for two problems.

1.  The line 'nextElem.focus();' generates an error, but works anyway.  
Here's the error text.
--------------   error text   -----------
Error: [Exception... "'Permission denied to get property 
XULElement.selectedIndex' when calling method: 
[nsIAutoCompletePopup::selectedIndex]"  nsresult: "0x8057001e 
(NS_ERROR_XPC_JS_THREW_STRING)"  location: "JS frame :: 
http://rer2.datacomp-intranet.com/js/util.js :: smartJump :: line 414"  
data: no]
----------------------------------------

2.  My routine gets the next form element based on source order, not 
based on tab order as specified by the tabindex attribute.

Any ideas about how to deal with these issues?

-----------  code  -------------
function smartJump(e, maxLen, skipVal, nextElem, flip) {
	if (arguments.length < 3) {
		skipVal = ""
	}
	if (arguments.length < 5) {
		flip = ""
	}
	
	var isNN = (e.target);
	if (!e) e = window.event;
	var myKeyCode = (isNN) ? e.which : e.keyCode;
	var mySource = (isNN) ? e.target : e.srcElement
	var filter = (isNN) ? [0,8,9] : [0,8,9,16,17,18,37,38,39,40,46];
	if((mySource.value.length >= maxLen) && 
!containsElement(filter,myKeyCode)) {
		mySource.value = trim(mySource.value.slice(0, maxLen));
		if (arguments.length < 4) {
			nextElem = null;
		}
		if(((flip == "flip") && ( mySource.value == skipVal )) ||
			((flip == "") && ( mySource.value != skipVal ))){
			nextElem = null;			
		}
		if (!nextElem) {
			nextElem = mySource.form.elements[(getIndex(mySource)+1)];
		}	
		nextElem.focus();  // <-- generates err in Moz, but works anyway
		nextElem.select();
	}
	return true;
}

function getIndex(input) {
	var index = -1, i = 0, found = false;
	while (i < input.form.length && index == -1) {
		if (input.form[i] == input) index = i;
		else i++;
	}
	return index;
}

TIA

Roger
-------------------------------------------------------
Roger Roelofs                 web   www.datacompusa.com
Datacomp Appraisal Services   web   www.mhvillage.com
3215 Eaglecrest Drive, NE     Email rer at datacompusa.com
Grand Rapids, MI  49525-4593 
  




More information about the Javascript mailing list