JavaScript Programming
JavaScript > Code Examples
Access an item in a collection
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Access an item in a collection
<html>
<head>
<title>Happy Codings :-) JavaScript Code Examples</title>
</head>
<body>
<form id="Form1" name="Form1">
Form1: <input type="text">
</form>
<form id="Form2" name="Form2">
Form2: <input type="text">
</form>
<p>
You can use the form's number:
</p>
<script type="text/javascript">
document.write("<p>The first form's name is: ")
document.write(document.forms[0].name + "</p>")
document.write("<p>The second form's name is: ")
document.write(document.forms[1].name + "</p>")
</script>
<p><b>Or, the form's name:</b></p>
<script type="text/javascript">
document.write("<p>The first form's name is: ")
document.write(document.getElementById("Form1").name + "</p>")
document.write("<p>The second form's name is: ")
document.write(document.getElementById("Form2").name + "</p>")
</script>
</body>
</html>