Deleting an option in a <select> list

Posted by Tyzak on Stack Overflow See other posts from Stack Overflow or by Tyzak
Published on 2010-06-10T10:45:11Z Indexed on 2010/06/10 15:42 UTC
Read the original article Hit count: 202

Filed under:

hello, i have following function:

function delete_auswahl()    
{

    var anzahl =document.getElementById ("warenkorbfeld").length ;

    for (var i =0; i<=anzahl; i++)
    {
        if (document.getElementById ("warenkorbfeld").options[i].selected==true)
        {



            if (document.getElementById ("warenkorbfeld").options[i].id == "Margherita" )
                gesamtbetrag = gesamtbetrag - 4;

            if (document.getElementById ("warenkorbfeld").options[i].id=="Salami"  )
                gesamtbetrag = gesamtbetrag - 4.50;

            if (document.getElementById ("warenkorbfeld").options[i].id=="Hawaii"  )
                gesamtbetrag = gesamtbetrag - 5.50;


            document.getElementById ("warenkorbfeld").options[i]=null;
            i--;// auf der gleichen stelle bleiben, da dass nächste feld nachrückt

        }
    }

    document.getElementById('gesamtbetrag').innerHTML=gesamtbetrag ;

}

before i added values with

function hinzu (pizza)
{
    NeuerEintrag = new Option(pizza, pizza, false, false);
    document.getElementById("warenkorbfeld").options[document.getElementById("warenkorbfeld").length] = NeuerEintrag ;

    if (pizza=="Margherita")
    {
        gesamtbetrag = gesamtbetrag + 4;
    }

    if (pizza=="Salami")
    {
        gesamtbetrag = gesamtbetrag + 4.50;
    }

    if (pizza=="Hawaii")
    {
        gesamtbetrag = gesamtbetrag + 5.50;
    }

    document.getElementById('gesamtbetrag').innerHTML=gesamtbetrag ;

}

now, in the delete function doesn't substract the price. despite this, all works.

what's wrong with this term?

if (document.getElementById ("warenkorbfeld").options[i].id == "Margherita" )
                gesamtbetrag = gesamtbetrag - 4;

thanks in advance

© Stack Overflow or respective owner

Related posts about JavaScript