PDA

View Full Version : Defining Field entry order on a form



thompa
03-08-2007, 06:51 PM
Hi there,

I am using a very useful script from Dynamic Drive for preventing the 'Enter' key submit a form prematurely; instead it advances to the next field.

onKeyPress="return handleEnter(this, event)"

in the 'input' or 'select' statement calls the function below.

-------------------------------------------------
<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah(nurul@REMOVETHISvolmedia.com)
* This notice must stay intact for use
* Visit http://www.dynamicdrive.com/ for full source code
***********************************************/

function handleEnter (field, event) {
var keyCode = event.keyCode ? event.keyCode : event.which ? event.which : event.charCode;
if (keyCode == 13) {
var i;
for (i = 0; i < field.form.elements.length; i++)
if (field == field.form.elements[i])
break;
i = (i + 1) % field.form.elements.length;
field.form.elements[i].focus();
return false;
}
else
return true;
}
</script>
---------------------------------------------------------------
Unfortunately, the form contains many entries- it is a score sheet for tennis matches.

It would be really good if I could define the field entry order so that each game could be entered rather than the field entry jumping about the form.

I was thinking of using an array to define the input id's - but don't know how to go about it....

Can anyone help?

thanks in anticipation,

Allan