/    Sign up×
Community /Pin to ProfileBookmark

doument.getElementById Breaking code

I have the following code

[CODE]if( depth > 140 )
{
document.getElementById(“divetimes”).innerHTML = (‘<p>There is no safe no decompression time for this depth.</p>’);
}
else
{
document.getElementById(“divetimes”).innerHTML = (‘<p>At that depth your no decompression limit is <em class = myclass2>’ + nodetime + ‘</em> minutes. You need to make a saftey if your down at least <em class = myclass3>’ + sstime + ‘</em> minutes.</p>’ );
};[/CODE]

Whenever either of them happens it breaks the code and does nothing and causes all code that follows to not get executed. I tried commenting them out and as long as the one that will be executed is commented out everything after it works. Things that are placed before this section still work fine.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@themightymanuelauthorOct 29.2013 — I actually found the problem. I had called the script before creating the element.
Copy linkTweet thisAlerts:
@rtretheweyOct 29.2013 — Try:
<i>
</i>if( depth &gt; 140 )
{
document.getElementById("divetimes").innerHTML = '&lt;p&gt;There is no safe no decompression time for this depth.&lt;/p&gt;';
}
else
{
document.getElementById("divetimes").innerHTML = '&lt;p&gt;At that depth your no decompression limit is &lt;em class = myclass2&gt;' + nodetime + '&lt;/em&gt; minutes. You need to make a saftey if your down at least &lt;em class = myclass3&gt;' + sstime + '&lt;/em&gt; minutes.&lt;/p&gt;';
};

The 'innerHTML' property needs to be a string. The browser may not like the parenthesis you were using. You also need to make sure that there is actually an element in the document with the 'id' attribute set to "divetimes".

In either case, you should have a debugging tool available to point out the error. MSIE comes with one in the F12 Developer Tools. Chrome and Firefox have add-ons available. Check them out and you'll find your error.
Copy linkTweet thisAlerts:
@themightymanuelauthorOct 29.2013 — I actually found the problem. I had called the script before creating the element.
×

Success!

Help @themightymanuel spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @nearjob,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...