"John Ryan" <celticfcNOSPAM@iol.ie> writes:
[color=blue]
> I've a small bit of javascript on my site that has a from with 2 selection
> boxes, when you choose an option in the first box, the second one
> re-populates its list accordingly.
>
> But the second selection box can have varying amounts of entries, and this
> means theres a lot of white spaces in the second selection box sometimes. Is
> there any way to eliminate this? Here's my code:[/color]
[color=blue]
>
> <script language="JavaScript1.2">[/color]
Unless you *know* the difference between JavaScript 1.2 and 1.3, you
probably don't want to use 1.2. Just write
<script type="text/javascript">
The "type" attribute is required in HTML 4, and it is sufficient.
[color=blue]
> var logos = new Array();
> logos[0] = "Abstract";
> logos[1] = "Adult";
> logos[2] = "Animals";[/color]
This can be written as just
var logos = [
"Abstract",
"Adult",
"Animals",
...
"Zodiac"
];
It is much shorter.[color=blue]
> function loadbox2(){
> //clearing loop
> for (i = 0; i < document.browse_form.category.options.length; i++){
> document.browse_form.category.options[i].text = "";
> document.browse_form.category.options[i].value = "";
> }//ends clearing FOR loop[/color]
To clear the options, either assign "null" to each, or just remove
them completely.
I.e., either (inside the loop)
document.forms['browse_form'].elements['category'].options[i] = null
or (instead of the loop)
document.forms['browse_form'].length = 0;
This removes the option elements, so you need to add new:
[color=blue]
> for (i = 0; i < array1.length; i++){
> document.browse_form.category.options[i].text = array1[i];
> document.browse_form.category.options[i].value = array1[i];[/color]
Change these two lines to:
---
document.forms['browse_form'].elements['category'].options[i] =
new Option(array1[i],array1[i]);
---
/L
--
Lasse Reichstein Nielsen -
lrn@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'