Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

multiple js files create a headache

Status
Not open for further replies.

xiaoleiqq

Programmer
Aug 30, 2006
43
US
I have two different js files, namely validate1.js and validate2.js, each have their own function call validate1() and validate2(), then I include them in the header, so it looks like this:

<head><title>input coordinates</title>
<script src = "validate1.js" type="text/javascript"></script>
<script src = "validate2.js" type="text/javascript"></script>

...

and later I use two forms, each calls the different function, as the following:

<FORM METHOD="POST" NAME="DD" ACTION="select.cgi" onsubmit="return validate1(this)">
...
</form>
and

<FORM METHOD="POST" NAME="DMS" ACTION="select.cgi" onsubmit="return validate2(this)" >
...</form>


unfortunately, js only looks for the later file (in this case validate2.js) for both of the function calls, and if I switch the script declaration order in the header, it will look for validate1.js only.

And the interesting part is the same function is being called by both form, (i.e. both form calls validate2() if the validate2.js is loaded last.

wondering what goes wrong here..

Thanks in advance.
 
huh..this forum dont support editing after post, i mean each file has one function respectively, as validate1.js have validate1() and validate2.js have validate2().


SOrry I didnt make myself clear
 
yeah sure, i have a different alert for each function

in validate1.js:
function validate1(form)
{
alert("1 is run");
if(check_lat(form, "not a valid latitude!") == false)
{return false;}
if (check_long(form, "not a valid longitude!") == false)
{return false;}
}

in validate2.js:
function validate2(form)
{
alert("2 is run");
with (form)
{
if (check_lat(latitude, "not a valid latitude!") == false)
{latitude.focus(); return false;}
if(check_long(longitude, "not a valid longitude!") == false)
{longitude.focus(); return false;}
}
}
 
Sigh...I used the same subroutine name...

THank you so much, really appreciate your help..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top