Multiple choice

Which of the following is the correct syntax to access an element of the form object?

  1. document.forms.element

  2. document.forms[0].elements[0]

  3. document[0].forms.element

  4. document.forms.elements[0]

  5. document.forms[0].element

Reveal answer Fill a bubble to check yourself
B Correct answer
Explanation

if a web document contains a form element it can be referred in JavaScript using the syntax -document.forms[0]

If the Web document contains two form elements the first form is referred to as document.forms[0] and the second document.forms[1]. Therefore we can access first form element using document.forms[0].elements[0], the second element can be accessed as document.forms[0].elements[1] and so on.