Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Java > Java and JDK > Pro Java
|
Pro Java Expert level Java questions not about a specific book. Please indicate your version.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Pro Java section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 1st, 2005, 05:51 AM
Authorized User
 
Join Date: Dec 2005
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via Yahoo to lameneural
Default Function expected!

Hi,

I hope I'm not lost.. I have a problem regarding my script(javascript). I dont understand why the error(Function expected) only appears on the second execution the function. Ex. I entered values(filenames) to boxes and try to upload it. But before that, I checked the files if they are really existing. on the first try, I clicked the button, the page prompted me (through alert();) that the file was not found. (Therefore, the code works...) But on the second time I click the same button, then I have the error "Function expected"!

Can you please help me on this?

Here's my code:
<script language="Javascript">

function try() {

    if (document.frm.box.value != '') {
        if (validateFile(document.frm.box.value)) {
            ok_flag = true;
        }
        else {
            alert("File was not found.");
            ok_flag = false;
            return false;
        }
    }

    if (ok_flag == true) {
        document.frm.submit();
    }
}

function validateFile(filespec) {
    validateFile = false;

    try {
        var fso = new ActiveXObject("Scripting.FileSystemObject");
        if (fso.FileExists(filespec))
            validateFile = true;
    }
    catch(err) {
        //alert(err.number + ": " +err.message);
        if (err.message == 'Automation server can\'t create object') {
                        alert("");
        }
        else {
            strMessage = "Unexpected error: " + err.message;
            alert(strMessage);
        }
    }

}

</script>

for the button:
<input name="btntry" type="button" value="Try" onClick="javascript:try();">

 
Old July 1st, 2006, 08:27 PM
Friend of Wrox
 
Join Date: Jan 2006
Posts: 198
Thanks: 0
Thanked 0 Times in 0 Posts
Default

It's kinda late to respond to you, but "try" is a reserved word and cannot be used as a function name.

Jon Emerson
http://www.jonemerson.net/





Similar Threads
Thread Thread Starter Forum Replies Last Post
expected Then Adam H-W Classic ASP Basics 6 April 17th, 2008 05:41 AM
expected ';' RoniR Javascript 3 February 1st, 2007 05:28 AM
Error: Function expected lameneural Java Basics 0 December 1st, 2005 06:57 AM
Expected 'Then' Adam H-W Classic ASP Basics 5 July 26th, 2004 02:36 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.