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 strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

.js file include not working but was before

Status
Not open for further replies.

simonTheTraveller

Programmer
Jun 29, 2006
16
GB
I created a validation routine held inside a separate js file so when all the different files (I'm working in jsp) forms were submitted they would be validated using this file.

It was working before with the following code:

<script language="javascript" src="../validation/checkAmount.js"></script>

The checkAmount file is located inside the validation directory which is held in the directory above where all the files are. All the files are located inside life_insurance/files.jsp

However, whenever I submit the form using the following:

<form action="return checkAmount(formElement)" ...

it doesn't find the file and just goes onto the next page. checkAmount() is the name of a function inside the file itself. I've tried creating dummy functions inside the file to just display alert boxes, but nothing!!!

This is just driving me crazy because previously it was WORKING!

The only thing I can think of is that its not pointing to the right file so I put the validation file inside the same directory as the jsp file so the script line read <script src="checkAmount.js"> but it still didn't work.

PLEASE HELP ME.
 
the call to your function should be in the onsubmit event.

Code:
<form action="blah.jsp" method="post" onsubmit="return checkAmount(...);">

if your code above was just mis-typed, it is most likely a path/naming issue.



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
sorry. My mistake. I have put the call to the function in the form method onSubmit as follows:

<form name="theForm" action="nextFile.jsp" onSubmit="return checkAmount(formElement);">

the file names are correct and the path is correct. I've tried putting the validation file in the same directory as the jsp file which makes the path easier. It still doesn't call it!!
 
do you have a link to your file? maybe you're getting another JS error when the page loads, which prevents JS from running? how do you know it's not being called? try putting an alert in the function.



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
the js file is in the directory
finance-navigator/validation/checkAmount.js

the jsp files are in the directory
finance-navigator/life-insurance/files.jsp

the line calling the js file from the jsp file is

<script language="javascript" src="../validation/checkAmount.js"></script>

I've tried putting the js file in the same directory as the jsp files so the path is just checkAmount.js not ../validation/checkAmount.js but it still doesn't work. I've also tried using a dummy function that just shows an alert box. NOTHING
 
Have you changed your doctype? perhaps using type="text/javascript" rather than language=...

Any changes on the server?
Sometimes the server is set to disallow the use of .. and you would have to use a relative path from the root web folder. Not a bad idea to test it with the full path anyway.



At my age I still learn something new every day, but I forget two others.
 
I tried changing the language="javascript" to type="text/javascript" but no effect. I tried using an absolute path from the root but no effect.

The thing is, up until about 12 o'clock today, all the function calls were working fine. I haven't changed a thing since then about the paths or function names. This leads me to believe that it can only be a problem with the server.

Any ideas?
 
any ideas? you really haven't given us much to work with. you've given us only hypotheticals. 99% of the time this problem is a path issue or a javascript error somewhere. i doubt it's something with the server because js runs client-side, which i'm sure you know. can you access the file directly (enter the url into the address bar)? can you provide us with a link to your page? there's not much more we can guess unless we get more information from you.



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
error from FireFox's javascript console:

[tt]Error: missing ) after condition
Source File: Line: 49, Column: 38
Source Code:
if(checkAmount(curElement==false){[/tt]

you need another closing semicolon:

Code:
if(checkAmount(curElement==false)[red])[/red]{



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
you've just made a grown man cry.

it works now.

thanks.

GEJPGEI)_}TO@|GPL}£"
L£P}{O)G£_)EI_)£GI)£I)@£IGF£{!!!!!!!!!!!!!!!!!!!!!!!!!!
 
stuck with developing on mac I'm afraid. I'm used to working in flash. Didn't realise that if any part of the js file was wrong it would stop it working.

In flash, does'nt matter if other functions are wrong as long as the one your calling is ok.
 
FireFox

Mac
Operating Systems

* Mac OS X 10.2.x and later

Minimum Hardware

* Macintosh computer with an Intel x86 or PowerPC G3, G4, or G5 processor
* 128 MB RAM (Recommended: 256 MB RAM or greater)
* 200 MB hard drive space



*cLFlaVA
----------------------------
[tt]( <P> <B>)[sup]13[/sup] * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top