www.webdeveloper.com
Results 1 to 3 of 3

Thread: What is the meaning - Error variable not defined?

  1. #1
    Join Date
    Aug 2005
    Posts
    59

    Smile What is the meaning - Error variable not defined?

    Hi,

    When I try this script I get an error saying that the variable is not defined. Can someone explain what is wrong?


    <HTML>
    <HEAD><TITLE>New Page 2</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>
    <META content=FrontPage.Editor.Document name=ProgId>
    <SCRIPT language=JavaScript>
    <!-- Alternative selection

    var alternative="";

    function changeValue(newValue)
    {
    alternative=newValue;
    }
    -->
    </SCRIPT>
    </HEAD>

    <BODY>
    <form>
    <input type='button' name='button1' value='English' onClick='javascript:changeValue(english)'>
    <input type='button' name='button2' value='German' onClick='javascript:changeValue(german)'>
    </form>

    <SCRIPT language="JavaScript">
    <!--
    document.write("<br>Choice is " + alternative);
    //-->
    </SCRIPT>

    </BODY>
    </HTML>

  2. #2
    Join Date
    Sep 2005
    Posts
    7
    To me it looks like these 2 lines...

    <input type='button' name='button1' value='English' onClick='javascript:changeValue(english)'>
    <input type='button' name='button2' value='German' onClick='javascript:changeValue(german)'>

    You need to pass them back to the changeValue function as a string, otherwise javascript thinks you are passing variables.

    changeValue("english")

  3. #3
    Join Date
    Feb 2005
    Location
    USA
    Posts
    1,534
    You did not put quotes (") around english and german so javaScript was expecting to find variables named so, is this what you are trying to do?

    Also, in event handlers javascript: protocol is redundant.

    Code:
    <HTML>
    <HEAD><TITLE>New Page 2</TITLE>
    <META http-equiv=Content-Type content="text/html; charset=windows-1252">
    <META content="Microsoft FrontPage 4.0" name=GENERATOR>
    <META content=FrontPage.Editor.Document name=ProgId>
    <SCRIPT language=JavaScript>
    <!-- Alternative selection
    function changeValue(newValue)
    {
    	document.getElementById("out").innerHTML = newValue;
    }
    -->
    </SCRIPT>
    </HEAD>
    
    <BODY>
    <form>
    <input type='button' name='button1' value='English' onClick='changeValue("english")'>
    <input type='button' name='button2' value='German' onClick='changeValue("german")'>
    </form>
    
    <br>Choice is <SPAN id="out"></SPAN>.
    
    </BODY>
    </HTML>

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