<!DOCTYPE html>
<
html
>
<
head
>
<
title
>
HTML | DOM forms Collection
</
title
>
</
head
>
<
body
>
<
h1
style
=
"color:green"
>GeeksForGeeks</
h1
>
<
h2
>DOM document.forms Property</
h2
>
<
form
id
=
"personal-info"
>
<
h3
>Personal Information Area</
h3
>
Name: <
input
type
=
"text"
>
</
form
>
<
form
id
=
"home-info"
>
<
h3
>Home Address Information Area</
h3
>
Address: <
input
type
=
"text"
>
</
form
>
<
form
id
=
"delivery-info"
>
<
h3
>Delivery Type Area</
h3
>
Delivery Speed: <
input
type
=
"text"
>
</
form
>
<
p
>
Click the button below to find
all form IDs:
</
p
>
<
button
onclick
=
"findFormIDs()"
>
Find form IDs
</
button
>
<
p
>The ID of all the forms is: </
p
>
<
div
class
=
"ids"
></
div
>
<
script
>
function findFormIDs() {
let final = '';
let collection = document.forms;
// Run a loop upto the number of
// forms in the collection
for (let i = 0; i <
collection.length
; i++) {
// Add each form id to the final list
final += `<li> ${collection[i].id} </
li
>`;
}
// Replace the inner HTML of the
// ID div to show the list
document.querySelector(".ids").innerHTML = final;
}
</
script
>
</
body
>
</
html
>