www.webdeveloper.com
+ Reply to Thread
Results 1 to 6 of 6
  1. #1
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    66

    What does "...is not defined" error mean?

    I'm having a problem testing some code I wrote. Here is the error...
    Error: translateEn is not defined
    Line: 1
    What does it mean 'not defined'? I have defined the function (I assumed), so what else is it referring to?
    ...and the code.
    Code:
    <script>
    var function translateEn() {
    document.getElementById("translateHeader1").innerText = translation.header1;
    document.getElementById("translateContent1").innerText = translation.content1;
    
    }
    
    // *** TRANSLATION ***************************
    var translation {
    header1: 'In English',
    content1: 'This text is in English.'
    }
    // *************************************************
    </script>
    
    <p>
    <button id="translateButton" onclick="translateEn()">English translation</button>
    </p>
    
    <h1 id="translateHeader1">Suomeksi</h1>
    <p id="translateContent1">Tämä texti on suomeksi.</p>
    Thanks in advance

  2. #2
    Join Date
    Dec 2003
    Location
    Bucharest, ROMANIA
    Posts
    15,427
    You missed the assignment operator within the object's syntax. Should be
    Code:
    var translation = {
    header1: 'In English',
    content1: 'This text is in English.'
    }
    The IE debugger is not accurate, this is the reason for that error message
    And I would have used innerHTML instead of innerText, for cross-browser compatibility reasons.

  3. #3
    Join Date
    Mar 2010
    Location
    Finland
    Posts
    66
    Thanks, and thanks for the extra tip.
    I got the error again, but realised I had also defined the function wrong. It's all working now though

  4. #4
    Join Date
    May 2006
    Location
    Russia, Rostov-on-Don
    Posts
    1,151
    var function translateEn() {
    use [code]YOUR CODE GOES HERE[/code] or burn in Hell

  5. #5
    Join Date
    Nov 2011
    Posts
    64
    Code:
    function translateEn()
    delete away the var

  6. #6
    Join Date
    Jan 2011
    Posts
    110
    Quote Originally Posted by leke View Post

    What does it mean 'not defined'? I have defined the function (I assumed), so what else is it referring to?
    [/CODE]
    Nothing else - it say that translateEn doesn't exist in this document realm, nor within its outside connections .

    And it never lies.

    Quote Originally Posted by leke View Post
    [CODE]<script>
    var function translateEn() {
    document.getElementById("translateHeader1").innerText = translation.header1;
    </script>
    you don't "var" prefix your function keywords because it's a reserved word and you cant use it for a variable name nor can the var keyword be left alone not even terminated without feeding it a variable name in any case - therefore "translateEn" is never created - therefore it doesn't exist -that's what "...is undefined" error report means in browser javascript. Of course it doesn't say "it doesn't exist" literally, because of the "this" omnipresence. Otherwise it most probably would.
    Last edited by Troy III; 04-25-2012 at 06:03 PM.

Thread Information

Users Browsing this Thread

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

     

Bookmarks

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