Get The Field Name in Javascript

I have form which contain 4 text fields i want to get the field name or field id not the value using java script. Anybody know how to do?

If document.formname.elements[i].value gets the value of the form field then document.formname.elements[i].name gets the name of the same form field

just substitute the actual name of the form for formname and put the number of the element within the form (starting from zero) into i.

If you want the ids then substitute id for value or name

sounds easily googleable?