[Racine des codes] [Page précédente]

Parcours form

/Html JavaSript/Parcours elements form/Parcours form.html
<html>
<head>
<script type="text/javascript">
function Parcours() {
  var nF, nE, FF, txt = "";
  for (nF=0; nF<document.forms.length; nF++) { // parcours les forms
    FF = document.forms[nF];
    txt += "<form> : " + FF.name + "\n";
    for (nE=0; nE<FF.elements.length; nE++) { // parcours les elts du form
      // Rq : ne pas faire un "for (cpt in FF.elements)" (tableau special : HTMLCollection)
      txt += "....<elt> : " + FF.elements[nE].name + "\n";
      if (typeof(FF.elements[nE].readOnly) != "undefined" && FF.elements[nE].readOnly)
      txt += "readOnly ----^\n";
      /* // En propre (DOM1) marche pas avec IE6
      if (typeof(FF.elements[nE].attributes['readonly']) != "undefined")
        txt += "===" + FF.elements[nE].attributes['readOnly'].specified + "\n";
      */
    }
  }
  alert(txt);
}

</script>
</head>
<body>
  <form name="FF1">
    <select name="select11">
      <option>1
      <option>2
    </select>
  </form>
  <form name="FF2">
    <input type="text" readonly="readonly" name="inputTXT21">
    <input type="text" readonly name="inputTXT22">
  </form>
  <form name="FFGO">
    <input type="button" name="ButtonGO" value="Parcours <form>" onclick="Parcours()">
  </form>
</body>
</html>
[edit]