www.webdeveloper.com
Results 1 to 4 of 4

Thread: doument.getElementById Breaking code

  1. #1
    Join Date
    Jul 2013
    Posts
    7

    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>' );	
    	};
    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.

  2. #2
    Join Date
    Jul 2013
    Posts
    7
    I actually found the problem. I had called the script before creating the element.

  3. #3
    Join Date
    Mar 2011
    Posts
    1,160
    Try:
    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>';	
    	};
    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.

  4. #4
    Join Date
    Jul 2013
    Posts
    7
    I actually found the problem. I had called the script before creating the element.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles