Dorward's Ramblings

Name that Field

Published on

Yesterday I was working on a form handler and needed to check the names of a number of fields in the (rather long) form. I could have poked at the source or used a DOM Inspector, but (for various reasons) it was easier to use a script.

I threw this together in the space of a couple of minutes and ran it through Firebug. Each field was then prefixed by its name and I had a quick reference while I built the rest of the handler.

function label(el) {
  for (var i = el.length - 1; i > -1; i--) {
    var b = document.createElement('b');
    var text = document.createTextNode(el[i].name);
    el[i].parentNode.insertBefore(b, el[i]);

Feel free to use it if you think it will help you.