Link to home
Start Free TrialLog in
Avatar of smoothcat11
smoothcat11

asked on

Call Javascript from a different file

Hello I want to call the following file from a different file:

<script language = "Javascript">
function validateForm(){

      var VCity=document.Form1.City
      var VState=document.Form1.State

      if ( VCity.value  == "") {
            VCity.value = ""
          alert( "Please fill in a city" )
              VCity.focus()
          return false;
      }
      
      
      if ( VState.value == "") {
            VState.value = ""
          alert( "Please fill in a state" )
              VState.focus()
          return false;
      }
      
    return true
}
 </script>



It validates a form.  I tried to name it validate.js and call it with the following:

<script language="JavaScript" type="text/javascript" src="graphics/validate.js"></script>

Do you know why this happens or how to fix it?  Thanks!
ASKER CERTIFIED SOLUTION
Avatar of basicinstinct
basicinstinct
Flag of Australia image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
you should not use text...jst use this alone
<script language="JavaScript" src="graphics/validate.js"></script>

and make sure that your file is in the specified folder
@jaiganeshsrinivasan

actually it is the 'language' attribute that has been deprecated, the 'type' attribute is the w3c standard way to do it, but there is no harm having both... if either of them were to go it should be 'language'
SOLUTION
Avatar of Pratima
Pratima
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
i think Business Intelligence(sorry - Basic Instinct) is right...the file should not contain the script tag...becos it is in the script tag that we are specifying the content....apologies...
Use semicolon in all the line..

function validateForm(){
      var VCity=document.Form1.City;
      var VState=document.Form1.State;

      if ( VCity.value  == "") {
            VCity.value = "";
          alert( "Please fill in a city" );
              VCity.focus();
          return false;
      }
           
      if ( VState.value == "") {
            VState.value = "";
          alert( "Please fill in a state" );
              VState.focus();
          return false;
      }
     
    return true;
}
siva_siva: As with the type attribute - not important.
Semicolons are only mandatory in event handlers like
onClick="var x=2
alert(x)"

which will not work unless you add ; after x=2

Also two statements on one line needs semicolon between them:

function alertTwo() {
  alert(a); alert(b)
}
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Forced accept.

Computer101
EE Admin