Maximum number of drop down items?

W

William

Is there a maximum number of allowable drop down menu items? Is this governed
by some memory configuration somewhere?

I'm trying to create dynamically a drop-down menu of 489 items. The following
script works fine with a few items, but does nothing when presented with all
of them.

<script type='text/javascript'>
function makeMenu() {
var w = document.getElementById('rmtoc')
var k = w.options[w.selectedIndex].value
if (k==0) {
var s = new Array()
s[0] = 'Choice 1'
s[1] = 'Choice 2'
s[2] = 'Choice 3'
s[3] = 'Choice 4'
s[4] = 'Choice 5' //etc., etc.; choices are assembled with PHP
for(i=0;i<s.length;i++) {
document.forms['barform'].showpop.options = new Option(s)
}
}
}
</script>

Thanks!

Wm
 
D

Daz

William said:
Is there a maximum number of allowable drop down menu items? Is this governed
by some memory configuration somewhere?

I'm trying to create dynamically a drop-down menu of 489 items. The following
script works fine with a few items, but does nothing when presented with all
of them.

<script type='text/javascript'>
function makeMenu() {
var w = document.getElementById('rmtoc')
var k = w.options[w.selectedIndex].value
if (k==0) {
var s = new Array()
s[0] = 'Choice 1'
s[1] = 'Choice 2'
s[2] = 'Choice 3'
s[3] = 'Choice 4'
s[4] = 'Choice 5' //etc., etc.; choices are assembled with PHP
for(i=0;i<s.length;i++) {
document.forms['barform'].showpop.options = new Option(s)
}
}
}
</script>

Thanks!

Wm

Perhaps you can adjust your script and use it in a stand alone version,
which will make 1 dropdown box for each number of options? It's a lot
of dropdown boxes, I know, but then you might be able to let everyone
else know? It might also help if you can obtain access to a JavaScript
debugging console (included in Firefox, which can be download from
www.getfirefox.com). This might tell you about any errors.

I am wondering if the problem you are experiencing isn't due to a limit
on the number of options you can have, but rather the number of times
your script can recurse before your browser starts seeing it as a
script that might never end. There are probably some simple methods you
can use to get around this problem. Like passing, say 100 options to a
function which will print them to the page. then repeat for all of the
other options.

Good luck.

Daz.
 
B

Bart Van der Donck

William said:
Is there a maximum number of allowable drop down menu items? Is this governed
by some memory configuration somewhere?

Yes, it's a browser memory issue. The best way to deal with this, is a
good dose of common sense; there is not something like a hard limit for
this. One should test the CPU results on different platforms and
browers in order to conclude what's acceptable.
I'm trying to create dynamically a drop-down menu of 489 items. The following
script works fine with a few items, but does nothing when presented with all
of them.
[...]

498 items should be far below the CPU problem zone on modern computers.

<form id="barform"><select name="showpop"></select></form>
<script type='text/javascript'>
var s = new Array();
for(j=0; j<498; j++)
s[j] = 'Choice ' + j;
for(i=0; i<s.length; i++)
document.forms['barform'].showpop.options = new Option(s);
</script>

But you wrote that the options are actually assembled by PHP. Why turn
to javascript then ? You can achieve what you want in PHP as well (the
options are populated from PHP anyhow):

<?
for ($j = 0; $j < 498; $j++) {
$s[] = 'Choice ' . $j;
}
echo "<select name=\"showpop\">\n";
for ($i = 0; $i < count($s); $i++) {
echo " <option value=\"$s[$i]\">$s[$i]</option>\n";
}
echo "</select>";
?>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,058
Latest member
QQXCharlot

Latest Threads

Top