tags:

views:

17

answers:

1

Following is the Script i am working that will indicate the Feature Detection for Firefox i created a Json list i want to call each to check in the script to see wehther its undefined or not but its not working can someone help me i am too much exhausted....!!

<html>
<head>
<script type="text/javascript">

var JsonList = 
{
    "CheckSet": [
        {
            "property": "azimuth",
            "result": 0 
        },
        {
            "property": "cue",
            "result": 0 
        } 
    ] 
};


function Check()
{
    //alert('working');
    var looptrav;
    var looplist = JsonList;
    var indicator = 0;

    for(looptrav = 0; looptrav < looplist.CheckSet.length; looptrav++)
    {
        if(typeof(looplist.CheckSet[looptrav].property) != "undefined") 
        {
            looplist.CheckSet[looptrav].result = 1;
            indicator = 1;
            document.write ("Result: "+looplist.CheckSet[looptrav].result);
        }
}

Check();
</script>
</head>
</html>
A: 

JsonList (or looplist) is an Object, not an Array, so it doesn't have a length property. It however does have a property CheckSet which you correctly access further on (with one exception) and which is an Array.

So you need to change

for(looptrav = 0; looptrav < looplist.length; looptrav++)

to

for(looptrav = 0; looptrav < looplist.CheckSet.length; looptrav++)

and change

looplist[looptrav].result = 1;

to

looplist.CheckSet[looptrav].result = 1;

EDIT: You are missing a closing } and it's probably not a good idea to document.write inside <head>.

Working example: http://jsfiddle.net/qjuVk/

RoToRa
Check the Code i made Changes a bit and your logic also but still not working i posted whole code if it will be done i will be free from like hell :-S!!
PhpSeeker
Lots of Thanks for your Help Shit i miss the Bracket :( thats why its bad to use a normal Editor :(...!Still Lots of Thanks :)...You saved a life :D!!
PhpSeeker