IE7 - "Remembering" Javascript variables

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

IE7 - "Remembering" Javascript variables

Post by SpecialK »

I have been having an issue with basic row highlighting in IE7.

Code: Select all

<script>  var dt = document.getElementById('mytable');  var dtRows = document.getElementById('mytable').getElementsByTagName('tr');   function highlightSelected(){    //loop through entire table and remove highlighting    id = document.getElementById('myid').value;     for(var i=0;i<dt.rows.length;i++){      dt.rows[i].style.backgroundColor= (i%2==0) ? '#c5c5c5' : '#eeeeee';    }        //get the selected row and highlight    if(id!=0){document.getElementById(id).style.backgroundColor='red';}  }    highlightSelected();</script>
each tr has this line set through PHP

Code: Select all

<tr id='$rowID' onclick='setSelected($rowID);'>
the page has a hidden form variable

Code: Select all

<input type='hidden' name='myid' id='myid' value='0'>
I find this to be straightforward. No problems with FF3 but in IE7. Once I load the page and click to highlight any row, there is no problems. If I navigate away and back to the page (or click on another page within the site) it seems to remember and rehighlight. Now a Javascript alert shows it isn't stored at the end of the script tag, but it may be something internal.
On another note, it seems javascript might be caching some ajax code I have done as well.

Could this be a setting in my IE locally or is there something with IE7? (I don't currently have easy access to IE6 to verify)
User avatar
novice4eva
Forum Contributor
Posts: 327
Joined: Thu Mar 29, 2007 3:48 am
Location: Nepal

Re: IE7 - "Remembering" Javascript variables

Post by novice4eva »

I had my hands on this perfect solution for ajax caching problem from some forum, its disrespectful of me to not recall the name of the person who game me this solution but i owe him(her :roll: ) a big time.

Code: Select all

 
//TO OVERCOME IE CACHING PROBLEM
//URL for the ajax
function checkURL(URL) 
{
    var re = URL.split('?');
    if(re.length>1)
        URL=URL+'&dummy='+new Date().getTime();
    else
        URL=URL+'?dummy='+new Date().getTime();
    return URL;
} 
 
The new(ever unique) argument seems to flush things up! For anything away from ajax, i think there is this solution with meta tags. You might want to google it, or maybe it's all here somewhere :D
User avatar
SpecialK
Forum Commoner
Posts: 96
Joined: Mon Sep 18, 2006 3:49 pm

Re: IE7 - "Remembering" Javascript variables

Post by SpecialK »

Thanks novice4eva. I came across a solution on a website that suggested to just using a post instead of a get.
http://ajaxian.com/archives/ajax-ie-caching-issue

I will have to try the GET with a dummy variable. Somewhere I was reading it as appending a timestamp to your URL but I was thinking they were talking about the filename. I guess after looking at the same problem for awhile my mind started going.

As for the other question. It turns out there was some legacy code that wasn't removed from a different test that named each row with a hidden variable the same name as myid. Once that was removed everything seemed to work good. I think because there was no id tag on those variables that FF3 was working getting the Id. Either way both problems have been solved.
Post Reply