www.webdeveloper.com
Results 1 to 3 of 3

Thread: trouble creating an external JS file

  1. #1
    Join Date
    Jun 2008
    Posts
    9

    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 ;
    	}
    }
    //-->
    And in the body:
    Code:
    <form id="dataRequest" name="f1" action="" enctype="multipart/form-data" method="POST" onsubmit="return checkform(this);">
    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 ;
    	}
    }
    And I called for it as such:
    Code:
    <script language="javascript" type="text/javascript" src="/includes/javaScript/validation.js"></script>
    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

  2. #2
    Join Date
    Jan 2007
    Location
    Wisconsin
    Posts
    2,120
    I'm pretty sure the following is redundant:
    HTML Code:
    ... language="javascript" type="text/javascript" ...
    I don't think 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.

    Edit:
    I tend not to use the language attribute anymore (just the type attribute). Though, I seem to recall the language attribute being case-sensitive. Is it possible that your browser is thrown by the uncapitalized language in the external version?
    Last edited by svidgen; 06-18-2009 at 09:47 AM.
    Jon Wire

    thepointless.com | rounded corner generator

    I agree with Apple. Flash is just terrible.

    Use CODE tags!

  3. #3
    Join Date
    Dec 2005
    Location
    FL
    Posts
    7,355
    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.

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