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!

not working after move from HTML to a file

Status
Not open for further replies.

xiaoleiqq

Programmer
Aug 30, 2006
43
US
After I move the JS code out of HTML into a file, the function stop working and I have no idea why this happen,

Here is the html code,
<head>
<script src="foo.js"></script>
...
<form ... onsubmit="return check(this)">


//////////////////////////////
//////////////////////////////
here is the js code:
function check_long(field, txt){
with (field){
if(!valeu || value < -180 || value > 180){
alert(txt);
return false;
}
else {return true;}}}

function check_lat(field, txt){
with(field){
if (!value || value < -90 || value > 90){
alert(txt);
return false;
}
else {return true;}}}

function check(form){
with (form){
if (check_long(longitude,"not a valid longitude!") == false){
longitude.focus();
return false;
}
if (check_lat(latitude, "not a valid latitude!") == false){
latitude.focus();
return false;
}}}

(this code working fine when inside the HTML file)

THank you for any suggestion.
 
To things I can think of (w/o testing your script :))

1. Does the external js file reside in the same directory as the html file using it? If not, remember the path before the script file name...

2. Try adding the type attribute to your script tag :

Code:
<script type="text/javascript" src="foo.js"></script>

Regards
 
Thanks for the response.
I checked my code, however it does not my problem here, maybe I should just leave the js in the HTML if I can't solve this problem...
 
yeah, do that. or, actually put some effort into determining what's wrong.

you've provided us only with *some* code which you *think* is relevant to your problem.

we can't be much help if we have to guess what your real code looks like.



*cLFlaVA
----------------------------
[tt]mr. pibb + red vines = crazy delicious![/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Thanks for all the effort,

I finally get it fixed..

The problem is this, I download the code from linux server, and this line (<form ... onsubmit="return check(this)">) is broken into two lines:
so it looks like
<form ... onsubmit="return
check(this)">
in windows editor, and when I upload it back, it adds another breakline character,
all I need to do is to put this into one line and it works fine now..

Again I appreciate greatly on your effort..
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top