jrolson Posted September 29, 2010 Share Posted September 29, 2010 I have this javascript code, function loadState() { var state = $.cookie('toggleState'); $('div.toggle').each(function(i) { $(this).toggle(state[i] == 'Y'); }); } But im getting an error message in Internet Explorer "state is null or not an object" on this line, $(this).toggle(state[i] == 'Y'); How do I fix this? Link to comment Share on other sites More sharing options...
0 sweetsam Posted September 29, 2010 Share Posted September 29, 2010 Use something else instead of 'state' Link to comment Share on other sites More sharing options...
0 +Majesticmerc MVC Posted September 30, 2010 MVC Share Posted September 30, 2010 You're assuming that a cookie called "toggleState" already exists. You need to check to see if state is not a null string or empty, and also ensure that the string is the correct length... function loadState() { var state = $.cookie('toggleState'); $('div.toggle').each(function(i) { if(state && state.length >= +i + 1) { $(this).toggle(state[i] == 'Y'); } else { //Set default toggle state here if we can't find the state for this toggle. } }); } Link to comment Share on other sites More sharing options...
Question
jrolson
I have this javascript code,
But im getting an error message in Internet Explorer "state is null or not an object"
on this line,
How do I fix this?
Link to comment
Share on other sites
2 answers to this question
Recommended Posts