473,394 Members | 1,841 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

Variables not declared and "undefined" property values

'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/redirect.aspx?i=9565&t=http%3a%2f%2fsubscribe.igng amespy.com%2ffcup%2fhitpoints.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
Nov 7 '05 #1
1 2605
David R wrote:
'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').

--
Rob
Nov 7 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

13
by: Don Vaillancourt | last post by:
What's going on with Javascript. At the beginning there was the "undefined" value which represented an object which really didn't exist then came the null keyword. But yesterday I stumbled...
1
by: Pavils Jurjans | last post by:
Hello, I am building custom hashtable class, and thinking about value retrieval issues. The thing is, that sometimes the hashtable value may contain value null. If someone is reading this value...
3
by: Mark Sullivan | last post by:
When I trace through a csharp program I came to a situation where a certain values has an "undefined value" as shown in the debugger DbgClr. I want to check this but the following statements did...
49
by: matty | last post by:
Hi, I recently got very confused (well that's my life) about the "undefined" value. I looked in the FAQ and didn't see anything about it. On...
0
by: Marty Meyers | last post by:
TIA for your help! Using PHP 4.3.9 doing some code cleanup on an existing site. I have reduced the problem to: This File is marty.php: <? class Refs { function scriptDir() { echo "Refs are...
3
by: William | last post by:
I tried to update a scrolling_list with the following: function saveText( scroll_list, t_area, listToBeUpdated ) { var updated = new Option(); updated.value = t_area.value; updated.text =...
9
by: Klaus Johannes Rusch | last post by:
IE7 returns "unknown" instead of "undefined" when querying the type of an unknown property of an object, for example document.write(typeof window.missingproperty); Has "unknown" been defined...
3
by: gsuns82 | last post by:
HI all, I tried to read an array from an external javascript file called read.js,The array was declared & as well as defined with some values inside the <script> tag of a html file. For an...
5
by: Pseudonyme | last post by:
Dear All : Ever had an httpd error_log bigger than the httpd access log ? We are using Linux-Apache-Fedora-Httpd 2006 configuration. The PHP lines code that lead too tons of errors are : ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.