MCQ Single Best Answer Easy

QWhat would the following JavaScript code produce?
function totalelements()  
{  
    var allgenders=document.getElementsByName("gender");  
    alert("Total Genders:"+allgenders.length);  
}  
<form>  
     <input type="radio" name="gender" value="male">  
     <input type="radio" name="gender" value="female">  
     <input type="button" onclick="totalelements()" value="Total Genders">  
</form>

ID: #5083 Javascript DOM & Event Handling MCQ 111 views
Question Info
#5083Q ID
EasyDifficulty
Javascript DOM & Event Handling MCQTopic

Choose the Best Option

Click any option to instantly check if you're correct.

  • B Error
  • C 2
  • D 1
Correct Answer: Option C

Explanation

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.

Share This Question

Challenge a friend or share with your study group.