...

View Full Version : using ENTER key instead of TAB to move on next element



TheJuan
10-24-2005, 08:03 AM
hi
i have this code using ENTER key instead of TAB to move on next form element which work fine on the IE but not working Firefox.
<input type="text" name="givename" onKeyDown="if(event.keyCode==13) event.keyCode=9;" />
<input type="text" name="surname" onKeyDown="if(event.keyCode==13) event.keyCode=9;" />

Seaching some page it says: "This is not working in Mozilla because the `event` object is a Microsoft proprietary trick". So what then is the same function on Mozilla? :thumbsup:

Kor
10-24-2005, 01:37 PM
see this example:


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<meta http-equiv="Content-Style-Type" content="text/css">
<meta http-equiv="Content-Script-Type" content="text/javascript">
<script type="text/javascript">
function tabE(obj,e){
var e=(typeof event!='undefined')?window.event:e;// IE : Moz
if(e.keyCode==13){
var ele = document.forms[0].elements;
for(var i=0;i<ele.length;i++){
var q=(i==ele.length-1)?0:i+1;// if last element : if any other
if(obj==ele[i]){ele[q].focus();break}
}
return false;
}
}
</script>
</head>
<body>
<form>
<input name="" type="text" onkeypress="return tabE(this,event)">
<input name="" type="text" onkeypress="return tabE(this,event)">
<input name="" type="text" onkeypress="return tabE(this,event)">
</form>
</body>
</html>



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum