Properti HTMLSelectElement.size
menetapkan atau mengembalikan atribut SIZE elemen SELECT HTML.
Sintaks:
selectObj.size = value
selectObj.size
value adalah number (long).
Contoh di bawah ini mengembalikan nilai atribut SIZE:
<FORM>
<SELECT SIZE="3" MULTIPLE>
<OPTION>0</OPTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>3</OPTION>
<OPTION>4</OPTION>
</SELECT>
</FORM>
<SCRIPT TYPE="text/javascript">
var selectObj = document.getElementsByTagName("select")[0];
alert(selectObj.size); // 3
</SCRIPT>
Contoh di bawah ini hanya tiga elemen OPTION saja akan ditampilkan, sisanya harus discroll. Pastikan properti HTMLSelectElement.multiple diset ke nilai true
:
<FORM>
<SELECT>
<OPTION>0</OPTION>
<OPTION>1</OPTION>
<OPTION>2</OPTION>
<OPTION>3</OPTION>
<OPTION>4</OPTION>
<OPTION>5</OPTION>
<OPTION>6</OPTION>
<OPTION>7</OPTION>
</SELECT>
</FORM>
<SCRIPT TYPE="text/javascript">
var selectObj = document.getElementsByTagName("select")[0];
if (selectObj.multiple === false) {
selectObj.multiple = true;
selectObj.size = 3;
}
</SCRIPT>