Question : size of listbox html

Hi, I am wondering if the following is possible. Code attached. I want a listbox just with the "select" as the default when entering the page. That is done. If you click the "Click me" button, options are added to the listbox from an array (See code). I would like it so that the listbox is a maximum of 10 entries before scrolling i.e size="10".

Otherwise I just get a massive listbox from the large number of items in the array.

Thanks.
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:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
<html>
<head>
<title>Page title</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<META HTTP-EQUIV="imagetoolbar" CONTENT="no">
<script type="text/javascript">

function add_branch_code(){

branch_codes="seven,eight,nine,ten,eleven,twelve,thirteen,fourteen,fifteen,sixteen,seventeen,eighteen,nineteen,twenty,twenty-one,twenty-two,twenty-three,twenty-four,twenty-five,twenty-six,twenty-seven,twenty-eight,twenty-nine,thirty,thirty-one,thirty-two,thirty-three,thirty-four,thirty-five,thirty-six,thirty-seven,thirty-eight,thirty-nine,forty,forty-one,forty-two,forty-three,forty-four,forty-five,forty-six,forty-seven,forty-eight,forty-nine,fifty,fifty-one";

split_branch_codes = branch_codes.split(",");

for(var a=0; a<split_branch_codes.length; a++) {
var selObj2 = document.getElementById("branch_code_listbox");
myOption2 = document.createElement("Option");
myOption2.text = split_branch_codes[a];
myOption2.value = a;
selObj2.add(myOption2,undefined);

                                               }

                           }


</script>

<style>
</style>

</head>

<body>


<form name="registration_form" method="post" action="registration.php">

	<div style="position:absolute; left:180px; top:100px; width:100px; visibility:visible;">
        <select name="branch_code_listbox" ID="branch_code_listbox" size="1" >
        <option value="Select">Select</option>
        <option value="One">One</option>
        <option value="Two">Two</option>
        <option value="Three">Three</option>
        <option value="Four">Four</option>
        <option value="Five">Five</option>
        <option value="Six">Six</option>
        </select>
	</div>


</form>

<div style="position:absolute; left:20px; top:20px">
<img src="images/test.gif" onClick="add_branch_code();">
</div>

</body>
</html>

Answer : size of listbox html

Hi Rupert,

I´m sorry having to say that this is definitely not possible this way. The decision of showing how many entries in a drop down box depends on the operating system and the browser. You can neither control this via HTML/CSS nor with JavaScript. It would be nice if this was possible, I wanted to use this some time ago, too. The browser also controls where the box is being shown (upper or lower the box).
Your only possibility is a multiple select box via size="10", size could be determined by JavaScript after adding the options, so that you don´t have empty lines.

Regards
Martin
Random Solutions  
 
programming4us programming4us