/    Sign up×
Community /Pin to ProfileBookmark

trouble creating an external JS file

I have a form with a validation script that works when it is in the <head> of the document but not when I relocate it to an external file. This is what I have in the <head> of the doc:

[CODE]<script language=”JavaScript” type=”text/javascript”>
<!–
function checkform ( form )
{

if ((form.requestType[0].checked == false )
&& (form.requestType[1].checked == false)
&& (form.requestType[2].checked == false))
{
alert (“Please choose a data request type”);
form.requestType[0].focus();
return false ;
}
}
//–>[/CODE]

And in the body:

[CODE]<form id=”dataRequest” name=”f1″ action=”” enctype=”multipart/form-data” method=”POST” onsubmit=”return checkform(this);”>[/CODE]

The JavaScript file that I created is simply this:

[CODE]function checkform ( form )
{

if ((form.requestType[0].checked == false )
&& (form.requestType[1].checked == false)
&& (form.requestType[2].checked == false))
{
alert (“Please choose a data request type”);
form.requestType[0].focus();
return false ;
}
}[/CODE]

And I called for it as such:

[CODE]<script language=”javascript” type=”text/javascript” src=”/includes/javaScript/validation.js”></script>[/CODE]

The code works fine embedded in the page but not as an external file. I’m sure that there is a simple syntax issue that I’m missing but I can’t figure it out. Any help is appreciated.

Thanks,
Todd

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@svidgenJun 18.2009 — I'm pretty sure the following is redundant:
[code=html]... language="javascript" type="text/javascript" ...[/code]
I don't [I]think[/I] that will prevent your script from working though. You should really just check your browser's error-log to see what's going on. I'd load the page in Firefox and check the error-log there, if I were you.

[B]Edit:[/B]

I tend not to use the [I]language[/I] attribute anymore (just the [I]type[/I] attribute). Though, I seem to recall the [I]language[/I] attribute being case-sensitive. Is it possible that your browser is thrown by the uncapitalized [I]language[/I] in the external version?
Copy linkTweet thisAlerts:
@JMRKERJun 18.2009 — Don't know if this will help, but needs to be asked:

  • 1. You do remove the redundant code in the <HEAD> section when calling the external version?


  • 2. The external file is located in the directory path specified? And spelled correctly?


  • 3. If on a server, you have set the permissions of the external file so that it is readable?

    I typically use permissions of '664' or '644' on my unix server.
  • ×

    Success!

    Help @leupi spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.16,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @nearjob,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,
    )...