Q:

Javascript jquery for loop problem

When i run this for loop it gives me the name bob and for jacob it says undefined does anyone have any idea why?
        $(function(){

        count = 1;

        for(x=0; x <= count; x++)
        {
            track = $('#track' + x).val();
            document.write(track);
        }

    });

    <input type="hidden" id="track0" value="bob" /> 
<input type="hidden" id="track1" value="jacob" />   

A:

Writing to document deletes your previous HTML. So , you cannot access the element by id anymore.
Alerting or writing it to some div instead of document gives proper response.
http://jsfiddle.net/KjHFM/
<span id='test'> RESULT : </span>

 $(function(){

    count = 1;

    for(x=0; x <= count; x++)
    {
        track = $('#track' + x).val();
        alert(track); // or $('#test').append(track+ "    ");
    }

});

