Hi all, totally baffled by this one!
I've got a bit of code:
xmlHttp.onreadystatechange=caravanSearchStateChanged;
xmlHttp.open("GET",url,true);
xmlHttp.send(null);
That fetches some html that's just been printed by an ASP page, and prints it to a div.There's some code afterwards:
if (document.getElementById('hideHeaders').value == '1') {document.getElementById('resultsHeader').className = ' none';}else {document.getElementById('resultsHeader').className = 'floatleft paddingtop15';}That checks a hidden HTML field for a 1 or a 0. If it's a 1, it hides a
div. If it's a 0, it shows a div. By default in the html, the field is
set to 0.Trouble is, the if statement is delayed. If I want to hide that div, I
have to wait for the condition to get a 1 twice. Vice-versa for the 0.However, if I put an alert saying "hello world!" between the two code snippets I gave you, it works!
It's almost as though the HTML is being written too late for the javascript to validate the if statement.
Trouble is, if I put a sleep function I found between those bits of code, it doesn't work.
What the hell is the problem here?
Any help's appreciated because I'm stuck!
Cheers,
Karl.
Hi,
The same problem is discussed athttp://forums.asp.net/p/1134520/1813795.aspx#1813795 &http://forums.asp.net/p/1134520/1813803.aspx#1813803
If yourHTML fieldis still not be shown,it is noneffective action at once to set the value of thefield.
The similar code in that post:
<script language="javascript" type="text/javascript">
// <!CDATA[function Button1_onclick() {
// This works
document.getElementById('div1').style.display = "block";
document.getElementById('div1').scrollLeft = 100;
// But this doesn't work
//document.getElementById('div1').scrollLeft = 100;
//document.getElementById('div1').style.display = "block";
}// ]]>
</script>
Best Regards
Thanks for taking a look at that for me; I've since found a solution and have written a small blog about it so that people are aware.
If you have any questions, reply to this post and I'll have a go at answering them.
http://codingrage.blogspot.com/2007/09/xmlhttprequest-object.html
Cheers,
Karl.
No comments:
Post a Comment