tags:

views:

27

answers:

2

Is there a way to remove the first options from this script:

http://javascript.internet.com/navigation/connected-comboxes.html

I want to remove the [ Type ] and [ Style ] options from the list and display other options only...

Can anyone please help?

+1  A: 

Remove the following lines:

    document.product.id_type.options[0] = new Option("[ Type ]");

    document.product.id_style.options[0] = new Option("[ Style ]");
JacobM
I tried but it displays empty options first...
Levani
it will still reserve a empty row at the first place. inorder to get rid of first option completely start i = 0 and some other coding tweaks e.g [i-1] to [i]
Ifi
Works fine, Thanks!
Levani
A: 

In addition to what is already suggested do some tweaks in code, set 1 =0 and if you also want to remove first empty option from second combo use j = 0

================================

function init(sel_type, sel_style){
    for(i = 0; i <= TypeArray.length; i++){
        document.product.id_type.options[i] = new Option(TypeArray[i].type, TypeArray[i].id);

        if(TypeArray[i].id == sel_type)
            document.product.id_type.options[i].selected = true;
    }

    OnChange(sel_style);
}


function OnChange(sel_style){
    sel_type_index = document.product.id_type.selectedIndex;
    sel_type_value = parseInt(document.product.id_type[sel_type_index].value);
    for(i = document.product.id_style.length - 1; i > 0; i--)
        document.product.id_style.options[i]    = null;
    j=1;
    for(i = 0; i <= StyleArray.length; i++){
        if(StyleArray[i].id_type == sel_type_value){
            document.product.id_style.options[j]    = new Option(StyleArray[i].style, StyleArray[i].id);

            if(StyleArray[i].id == sel_style)   document.product.id_style.options[j].selected = true;

            j++;
        }

    }
}
Ifi