Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

catching enter key pressed

Status
Not open for further replies.

malonep

Programmer
Jul 14, 2004
44
CA
Hi,

i have a page that when the enter key is pressed it moved down to the next textbox.

It works good for windows netscape/ie and mac ie but when I test it on a mac using safari when the enter key is pressed the whole page refreshes and any information that is entered is lost.
I have caught the enter key by the following code.

Does anyone know why only mac safari would be reloading the page and how to stop it from happening.

Code:
var nextGrade, netscape, ver, len, iln;
	var inputField;
	nextField= "txtField-99";
	netscape = "";
	ver = navigator.appVersion;
	len = ver.length;
	for(iln=0; iln < len; iln++){
		if (ver.charAt(iln) == "(")
			break;
	}
	netscape = (ver.charAt(iln+1).toUpperCase() != "C");
	
	function keyDown (DnEvents){
		var key;
		key = (netscape) ? DnEvents.which : window.event.keyCode;
		if (key == 13){ //the enter key
			if (nextField == 'txtField-99'){
				return true;
			}
			else{
				try{
					eval('window.document.gbIndvGradesEntryMiddle.' + nextField+ '.select()');
				}
				catch(er){
					alert("Cannot move to next Field.");
				}
				return false;
			}
		}
	}
	
	document.onkeydown = keyDown;

A sample of how I set up the textboxes
Code:
<input type="text" name = "<%=cstr("txtField" & trim(rs4.Fields("cFieldid")))%>" id = "<%=cstr("txtField" & trim(rs4.Fields("cFieldid")))%>" 
   	value= "<%=nValue%>" 
   	onblur="FieldCheck(this,'<%=iID%>');"   	onFocus="nextField='txtField<%=iID%>';">

any help would be appreciated
 
Maybe it's the VB interpretor that fails rather than the JS engine??!!

Have a go in the VBscript forum - forum329

Best Regards


Jakob
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top