js object problem

Posted by haltman on Stack Overflow See other posts from Stack Overflow or by haltman
Published on 2011-03-03T15:11:22Z Indexed on 2011/03/03 15:25 UTC
Read the original article Hit count: 295

Filed under:
|

Hi everybay!

I use an object to check that a group of radio buttons have a precise value like set on "rule" object. Here is an example:

arr = {a:"1", b:"1", c:"1", c:"2"}; //that's my object rule

var arr2={}; //here  I create my second array with charged value 
$("#form_cont input:checked").each(function()
{
    arr2[$(this).attr("name")]=$(this).val();
});
//here I make the check
for (k in arr2)
{
    if (typeof arr[k] !== 'undefined' && arr[k] === arr2[k]) 
    {
        $("#form_cont li[name$='"+k+"']").css('background-color', '');
    }
    else
    {
        $("#form_cont li[name$='"+k+"']").css('background-color', 'pink');
    }
}

The problem is when I have to check the "c" key I get last the one (2) and not the right value how that may e 1 or 2

thanks in advance

ciao, h.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about object