HTML DOMフォームの長さプロパティは、フォーム内に存在する要素の数を返すために使用されます。読み取り専用のプロパティです。
構文
以下は、フォームの長さプロパティの構文です-
ormObject.length
例
フォームの長さプロパティの例を見てみましょう-
<!DOCTYPE html>
<html>
<head>
<style>
form{
border:2px solid blue;
margin:2px;
padding:4px;
}
</style>
<script>
function getLength() {
var len=document.getElementById("FORM1").length ;
document.getElementById("Sample").innerHTML = "Number of elements present inside the form are :"+len;
}
</script>
</head>
<body>
<h1>Form length property example</h1>
<form id="FORM1">
<label>User Name <input type="text" name="usrN"></label> <br>lt;br>
<label>Password <input type="password" name="pass"></label> <br><br>
<select name="Fruit">
<option value="Mango">Mango<option>
<option value="Litchi">Litchi</option>
<option value="Guava">Guava</option>
</select>
</form>
<br>
<p>Get the number of elements present in the above form by clicking the below button</p>
<button onclick="getLength()">get Length</button>
<p id="Sample"></p>
</body>
</html>