document.forms-rajapinnan käytöstä on ollut hieman epäselvyyttä. Kannattaa vilkaista tämä luentopätkä, jossa asiaa selitetään:
https://appro.mit.jyu.fi/tiea2120/luennot/forms/#TOC7
Tarkoitus ei ole tehdä lomakekenttien käsittelyä hankalammaksi vaan helpottaa sitä. document.forms-rajapinnan kautta on helppo käsitellä input-, fieldset-, textarea- ja select-elementtejä ja niihin syötettyjä arvoja.
lomakkeiden testaamista voi myös hitusen helpottaa, jos laittaa autocompleten pois päältä, koska autocomplete välillä sotkee virheilmoitusten näyttämistä yms.
<form method="..." action="..." autocomplete="off">
Samoin muistakaa, että lomakkeen submit-tapahtuma ei oletuksena tapahdu, jos lomakkeen sisältö rikkoo rajoitteita. Esim. pakolliseen kenttään ei ole syötetty mitään. Ts. selain automaattisesti validoi lomakkeen eikä suorita submit-tapahtumaa, jos lomake ei ole validi. Tämän voi halutessaan estää asettamalla lomakkeelle novalidate-html-attribuutin. submit-painikkeen click-tapahtuma tapahtuu kyllä aina eli myös siihen voi yhdistää tarkistuksia.
https://appro.mit.jyu.fi/tiea2120/luennot/forms/#TOC13
Muistakaa myös mitä eroja on seuraavilla:
input.setAttribute("checked", ""); // asettaa oletusarvona valituksi
input.defaultChecked = true; // sama kuin edellä oleva setAttribute
// seuraava tekee valinnan eli sama kuin käyttäjä tekisi valinnan
input.checked = true;
Esim. jos lomake resetoidaan, niin se palaa alkuasetuksiinsa ja radiobuttoneista valituksi tulee se jolle on asetettu tuo checked-html-attribuutti tai defaultChecked-javascript-property.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement