
August 2nd, 2007, 12:20 PM
|
|
Registered User
|
|
Join Date: Aug 2007
Posts: 1
Time spent in forums: 35 m 42 sec
Reputation Power: 0
|
|
|
ImageBtn has no properties
Let me say first, that I am pretty sure what the problem is however I do not know how to solve it.
The problem:
The problem is that I am getting this error "ImageBtn has no properties" during my Javascript execution because the < DIV > it is in is initially HIDDEN.
What I am doing:
I am using AJAX to request information from a database on the server, and using what is returned from the server to Make Image buttons appear at the bottom of the screen. I have all of the Image buttons contained within a < DIV > and am making it visible (the div is initially set invisible) when I set the attributes for the Image buttons.
How do I get this working? Here is some of the code:
Code:
//This is the callback from AJAX
function ParseBuildingInfo()
{
//readyState of 4 or 'complete' represents that data has been returned
if (objXmlHttp.readyState == 4 || objXmlHttp.readyState == 'complete')
{
var strUpgrade = objXmlHttp.responseText.split( '\n' );
for( i=0; i<strUpgrade.length; i+=6 )
{
var ID_arr = i / 8;
i++;
showdiv( "Building_Upgrades" );
// The array IDs contains all the IDs after ASP.NET is done making them unique.
var ImageBtn = document.getElementById( IDs[ID_arr] );
ImageBtn.title = strUpgrade[i+1] + '\n' + "W:" + strUpgrade[i+2] +
" I:" + strUpgrade[i+3] + " S:" + strUpgrade[i+4] + " G:" + strUpgrade[i+5] + " Time:" + strUpgrade[i+6];
ImageBtn.src = strUpgrade[i+1];
}
}
}
//This is how I am hiding my . Show div is the same except it uses "block"
function hidediv(id)
{
//safe function to hide an element with a specified id
if (document.getElementById)
{
// DOM3 = IE5, NS6
document.getElementById(id).style.display = 'none';
}
else
{
if (document.layers)
{
// Netscape 4
document.id.display = 'none';
}
else
{
// IE 4
document.all.id.style.display = 'none';
}
}
}
As a side note, how do I prevent javascript from converting the '/' in the url to %5C. Ex. In my script above, when setting the ImageBtn.src, javascript inserts "%5CImages%5CbtnBuilding1.PNG" but on the DB it is "\Images\btnBuilding1.PNG"
I hope my intentions are clear enough.
Thank you for your help!
|