|
From: Kroska on 24 Jun 2008 15:58 Can I make a array with all form elements? to event keydown I think use esc[27] to return or enter[13] to next field.(my client order it) To my tast it is bad but .. I can´t to oppose. How I can write a array with all form elements and after to work with each item? x = document.forms[0].elements x = document.forms[0].elements.length can someone help me?
From: Jeff on 24 Jun 2008 21:22 Kroska wrote: > Can I make a array with all form elements? > > to event keydown I think use esc[27] to return or enter[13] to next > field.(my client order it) > To my tast it is bad but .. I can�t to oppose. > > How I can write a array with all form elements and after to work with > each item? > > x = document.forms[0].elements > > x = document.forms[0].elements.length You are close. document.forms[0]. Jeff > > can someone help me?
From: RobG on 24 Jun 2008 22:16 On Jun 25, 5:58 am, Kroska <kro...(a)gmail.com> wrote: > Can I make a array with all form elements? > > to event keydown I think use esc[27] to return or enter[13] to next > field.(my client order it) > To my tast it is bad but .. I can´t to oppose. > > How I can write a array with all form elements and after to work with > each item? > > x = document.forms[0].elements That returns an HTML collection of all the controls in the form: <URL: http://www.w3.org/TR/DOM-Level-2-HTML/html.html#ID-76728479 > An HTML collection is an array-like structure that you can use to access each control by index. The index is assigned based on the control's position in the DOM (essentially the order they appear in the HTML). > x = document.forms[0].elements.length The length property tells you how many controls are in the collection, so: var x = document.forms[0].elements for (var i=0, len=x.length; i<len; i++) { var control = x[i]; // do stuff with the control } As the elements collection is live, the length property will change if controls are added or removed from the form. So if "do stuff" adds or removes controls, you'll have include logic to handle that. -- Rob
|
Pages: 1 Prev: Need Help with Calculator Java Script Next: Access Denied |