Nait87
Nait87

Reputation: 13

onclick in a checkbox doesn't work in IE

I make an event handler onclick and IE 9,8,7 event starts work only when I turn on the console when I turn it off will work too. How can I solve this problem? Thank you! There is my code:

function changeCheck(id) // onClick функция акт/деакт. checkbox
{
    //checkbox = $('span#'+id).children().eq(0); // получаем checkbox в объект
    checkbox = $('span#'+id).children().eq(0); // получаем checkbox в объект
    console.log(checkbox);
    if(checkbox.attr('rel') !='nosumm') 
    {
        var totalSum = parseInt($('div#stoim').children().text()); // получаем начальную стоимость        
        if(!checkbox.attr('value').length) // если кликнули по "платежным системам" 
        {
            if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
            {
                checkbox.checked=true;
                $('span#'+id).css('background-position','0 -22px');
                if(checkbox.attr('checked','checked'))
                {
                    $('div#type_plati').slideDown();
                }
            }
            else // если checkbox отмечен
            {
                $('span#'+id).css('background-position','0 0');
        for(var key in paysystem)
        {
                    if($('input#choise'+paysystem[key]).attr('value') && $('input#choise'+paysystem[key]).is(':checked')==true)
                    {
            //console.log($('input#choise'+paysystem[key]).attr('value'));
            //console.log($('input#choise'+paysystem[key]).is(':checked'));
            totalSum = totalSum - parseInt($('input#choise'+paysystem[key]).attr('value'));         
                    }
                    $('span#niceCheckbox'+paysystem[key]).css('background-position','0 0');
                    $('span#niceCheckbox'+paysystem[key]).children().eq(0).removeAttr('checked');
                }
                $('input#subTotal').val(totalSum); // Записуем финальную цену на отправку
                $('div#stoim').children().text(totalSum);           
                if(checkbox.removeAttr('checked')) $('div#type_plati').slideUp(); 
            }        
        }
        else
        {
            if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
            {
                checkbox.checked=true;
                $('span#'+id).css('background-position','0 -22px');
                checkbox.attr('checked','checked');
                if(checkbox.attr('checked','checked'))
                {
                    totalSum = totalSum + parseInt($(checkbox).attr('value'));
                    $('div#stoim').children().text(totalSum);
                }
            }
            else // если checkbox отмечен
            {
                $('span#'+id).css('background-position','0 0');
                if(checkbox.removeAttr('checked'))
                {
                    totalSum = totalSum - parseInt($(checkbox).attr('value'));
                    $('div#stoim').children().text(totalSum);
                }
             } 
            $('input#subTotal').val(totalSum); // Записуем финальную цену на отправку
            $('div#stoim').children().text(totalSum);           
        }
    }
    else // обычные checkbox
    {
        if((checkbox).is(':checked') == false) // если еще не отмечено, то отмечаем
        {
            checkbox.checked=true;
            $('span#'+id).css('background-position','0 -22px');
            checkbox.attr('checked','checked');
        }
        else // если checkbox отмечен
        {
            $('span#'+id).css('background-position','0 0');
            checkbox.removeAttr('checked');
        }  
    }    

}

There is html code:

<li><span class="niceCheck"  onclick="changeCheck(this.id)" id="niceCheckbox2" rel=""><input type="checkbox" name="ch1" id="ch1" value="370"/> <label  for="ch1">Форма обратной связи</label></span></li>

Upvotes: 0

Views: 292

Answers (1)

bardiir
bardiir

Reputation: 14782

There is a console.log(checkbox); in your code thats not commented out.
This will break the code in IE if there is no console.

And since you're already using jQuery you might want to take a look at the .change() function/event in the documentation: http://api.jquery.com/change/
This could be what you want to use in the first place.

Upvotes: 1

Related Questions