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.Stat e
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!
<script language = "Javascript">
function validateForm(){
var VCity=document.Form1.City
var VState=document.Form1.Stat
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"
Do you know why this happens or how to fix it? Thanks!
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
@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'
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
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.Stat e;
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;
}
function validateForm(){
var VCity=document.Form1.City;
var VState=document.Form1.Stat
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)
}
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
<script language="JavaScript" src="graphics/validate.js"
and make sure that your file is in the specified folder