function not defined error in mozzila

Discussion in 'JavaScript' started by rahulm11, Feb 12, 2009.

  1. #1
    hi frnds,

    i am getting "closeMe is not defined error" while checking in firefox

    i am posting my code below


    <html>
    <head>


    <title>File Upload</title>
    <script language="text/javaScript">

    function closeMe()
    (
    window.location = $donePage;
    )
    </script>
    </head>

    <body>
    <p>your file $filename was successfully imported </p>
    <input type="button" VALUE="Done" onClick="javaScript:closeMe()" />



    </body>
    </html>


    basically i am wokring on a CMS called interwoven ,and i want to refresh the CURRENT DIRECTORY in which i am working after uploading some file thr a custom utility which i have developed in CGI ,now i just need to refresh the form ,

    the $donepage is the path for refreshing the page

    pls guide me if there is a way to just refresh the page and go back to current directory in javascript or atleast why this closeme is coming undefined when i have defined it and caling it correctly

    looking forward for a favorable response from your side

    regards,
    rahul
     
    rahulm11, Feb 12, 2009 IP
  2. dimitar christoff

    dimitar christoff Active Member

    Messages:
    882
    Likes Received:
    62
    Best Answers:
    0
    Trophy Points:
    90
    #2
    when you define the function why dont you use { } but ( )? does $donePage come with quotes/encapsulation, because if it's a string... it needs this in js.

    function closeMe()
    (
    window.location = $donePage;
    )

    should be:
    
    var closeMe = function() {
        window.location.href = "$donePage";
    };
    PHP:
    it is probably not defined because you have fatal exceptions on the page so js execution has ended prematurely.
     
    dimitar christoff, Feb 12, 2009 IP
  3. GreatMetro

    GreatMetro Peon

    Messages:
    117
    Likes Received:
    3
    Best Answers:
    0
    Trophy Points:
    0
    #3
    should be

    <script type="text/javascript">
     
    GreatMetro, Feb 12, 2009 IP
  4. mmerlinn

    mmerlinn Prominent Member

    Messages:
    3,197
    Likes Received:
    819
    Best Answers:
    7
    Trophy Points:
    320
    #4
    First, you are using parenthesis where you should be using brackets:

    [B][COLOR="Blue"]<html>
    <head>
    
    
    <title>File Upload</title>
    <script language="text/javaScript">
    
    function [COLOR="Red"][B]klose[/B][/COLOR]Me() [COLOR="Red"][B]{[/B][/COLOR]      [COLOR="Red"][B]<< Bracket should be here for ease of reading[/B][/COLOR]
         window.location = $donePage;         [COLOR="Red"][B]<< Indentation[/B][/COLOR]
    [COLOR="Red"][B]}[/B][/COLOR]
    </script>
    </head>
    
    <body>
    <p>your file $filename was successfully imported </p>
    <input type="button" VALUE="Done" onClick="javascript:[COLOR="Red"][B]klose[/B][/COLOR]Me()" />
    
    
    
    </body>
    </html>[/COLOR][/B]
    Code (markup):
    Second, "close" IS a reserved word in js. So you should NEVER use anything like it in your code. Use "kloseMe" instead. I know from experience - took me days to realize that "close" refers to "window.close" and would not work in FF as a function name.

    Third, use indentation to make your code easier to read.
     
    mmerlinn, Feb 15, 2009 IP