PDA

View Full Version : utilising tabindex to move through fields in a form



mgmidget
Jul 25th, 2012, 12:59 PM
I've found this script:

http://www.dynamicdrive.com/dynamicindex16/disableenter.htm


<script type="text/javascript">

/***********************************************
* Disable "Enter" key in Form script- By Nurul Fadilah([email protected])
* 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>

So that when people hit the enter button the focus moves to the next field in the form.

Unfortunately, this doesn't follow the tabindex.

How would the script be modified to follow the tabindex?

Many thanks

Calvert Tripesi
Jul 25th, 2012, 01:49 PM
How would the script be modified to follow the tabindex?

You could just try one that does that (http://scripterlative.com/files/entertotab.htm).