Variables not declared and "undefined" property values

D

David R

'lo

This one is confusing me, causing 2 separate errors:

Consider this XHTML and Javascript:

<!-- ########################## -->
<!-- SNIP -->
<head>
<script type="text/javascript"
src="http://login.gamespyid.com/ads/jscheck.aspx"></script>
<script type="text/javascript"
src="http://wrapper.gamespyid.com/a?pagetype=ccontent&amp;size=468x60"></script>
<script type="text/javascript" src="GSScripts.js"></script>
</head>
<html>
<!-- SNIP -->
<ul id="ex_Subscribe">
<li><a href="Foo">Buy Games</a></li>
</ul>
<!-- SNIP -->
</html>
<!-- ########################## -->
The 1st Gamespy javascript *requires* a HTTP Referer (sic) field to be
present, fake any if you wish.

GSScripts.js contains this:

/////////////////////////

var legalsite = "NewPlanetSite";
var advertise = "/site/contact.shtml#ads";
var legal = "/site/legal.shtml";
var strAdsEnabled = "";
var strUpgradeLink = "";
window.onload = function() {
if ( adsAreDisabled ) {
strAdsEnabled = '<li><a
href="https://login.gamespyid.com/ads/ads.aspx?off=1">Enable Ads</a></li>';
} else {
strAdsEnabled = '<li><a
href="https://login.gamespyid.com/ads/ads.aspx">Disable Ads</a></li>';
}
if ( isLoggedIn ) {
strUpgradeLink = '<li><a
href="https://login.gamespy.com/Subscribe/upgrade.aspx">Upgrade
Now!</a></li>';
} else {
strUpgradeLink = '<li><a
href="http://net.gamespyid.com/linktrack/.../subscribe.igngamespy.com/fcup/hitpoints.html">Subscribe
Now!</a></li>';
}
var ulEx = document.getElementById("ex_Subscribe");
ulEx.InnerHtml = ulEx.InnerHtml + strAdsEnabled + strUpgradeLink;
}

/////////////////////////

And guess what?

It doesn't work! XD

The 2 problems are:

a) The "adsAreDisabled" variable declared and assigned in jscheck.aspx are
not carried over to GSScripts.js, so it throws an NRE error for the "if
(adsAreDisabled) {" line. Is there any workaround for this? (To see problem
#2 just comment out all the "if" and brace lines)

b) Setting the .InnerHtml property doesn't do anything; I did an "alert (
strAdsEnabled );" and that worked. But when I did "alert (
ulEx.InnerHtml );" I got "undefined". However, "alert ( ulEx );" works fine.

Any ideas?

Thanks
 
R

RobG

David said:
'lo

This one is confusing me, causing 2 separate errors:
[...]

And guess what?

It doesn't work! XD

The 2 problems are:

a) The "adsAreDisabled" variable declared and assigned in jscheck.aspx are
not carried over to GSScripts.js, so it throws an NRE error for the "if
(adsAreDisabled) {" line. Is there any workaround for this? (To see problem
#2 just comment out all the "if" and brace lines)

I can't test this, but it could be that the jscheck.aspx script has not
loaded when your anonymous function is executed (the right hand side
will be evaluated & executed immediately it is parsed, not when the page
has finished loading).
b) Setting the .InnerHtml property doesn't do anything; I did an "alert (
strAdsEnabled );" and that worked. But when I did "alert (
ulEx.InnerHtml );" I got "undefined". However, "alert ( ulEx );" works fine.

JavaScript is case sensitive: the property you seek is elEx.innerHTML
(lower case 'i').
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,767
Messages
2,569,572
Members
45,046
Latest member
Gavizuho

Latest Threads

Top