faqts : Computers : Programming : Languages : JavaScript : Forms

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

12 of 15 people (80%) answered Yes
Recently 8 of 10 people (80%) answered Yes

Entry

How can I reference the field before or after the current one without knowing the name?
How do I send the info from one text field in a form to multiple fields of a flatfile database
How do I send the info from one text field in a form to multiple fields of a flatfile database

Oct 24th, 2000 21:44
Tim Powell, Tudor Holton, Kev Choppin,


The elements array of the form contains all the fields in a form. You 
can use a function to find the current field in the array and then 
access the previous or next one by number. 
For example, to find the next element, pass a reference to the current 
element to this function:
function nextElement(el)
{
   var current = 0;
   var frm = el.form;
   for (var i=0; i < frm.length; i++)
   {
	if (frm.elements[i] == el)
	{
		current = i;
		break;
	}
   }
   return (current+1)
}