MCQ Practice Single Best Answer Topic: Javascript DOM & Event Handling MCQ

Q What 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>

Question ID
#5083
Subchapter
Javascript DOM & Event Handling MCQ
Action
Choose one option below

Choose Your Answer

Click an option to check whether your answer is correct.

  • B Error
  • C 2
  • D 1
Correct Answer: 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

Share this MCQ with your friends or study group.