function totalelements() { var allgenders=document.getElementsByName("gender"); alert("Total Genders:"+allgenders.length); }
All elements with the supplied name are returned by the document.getElementsByName() function. The code stated above counts all of the output specified in the form.