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 - Validation Fails-Works when Embedded in Page 2

Status
Not open for further replies.

dougcranston

Technical User
Oct 5, 2001
326
US
Hope someone can point me to a logical answer and solution.

I had built client-side validation and had embedded in <script></script> tags located in the <head> of my page and it worked fine.

I then moved some business rules that controlled checkboxes and stuff to an external .js file. Continued testing and that worked fine.

Then I moved my validation code from the internal/embedded to a separate .js file, reference in my page looked like:

<SCRIPT
type=&quot;text/javascript&quot;
language=&quot;JavaScript&quot;
src=&quot;includes/vldprcrqst.js&quot;></SCRIPT>

However, then my validation stopped working. Would not even call it. (Added an alert as the first line of the validation function.. nothing.) Just bypassed it totally and tried to send the data on to my ASP page which REALLY did not like it..

Put the validation code back in its original spot embedded in the <head> of my page and it works fine.

A portion of the calling onSubmit is as follows:
<FORM name=&quot;frmInput&quot; action=&quot;crft.asp&quot; method=&quot;post&quot;
onSubmit=&quot;return validcheks(reqType.value, ItemID.value, ......


Had wanted to keep the web page, a .htm just HTML code, and move the .js, and .css to external files, but this one has been plaguing me the past day, and I was bound and determined NOT to move the validation code back.

In the final analysis I can keep it embedded, but it feeling right to have the rules, validation and css external to the HTML page, since this is huge as one file. This is not the way I want to do it. However, it is an intranet app, and will be used only by a select # of users to input new products to be added to our point of sale system. Bandwidth and CPU time on the staff PC's is not as much of an issue.

I would post the code, but at the moment it is over 140K, which breaks out:

42k html (sans validation)
23k validation.js
53k business rules.js
7k stylesheet .css
22k calendar.js

I have checked this site relative to external includes and validation, but nothing close. Have searched google, and my reference books, both HTML and Javascript and no hints or ideas.

Any suggestions would be appreciated.

Thanks inadvance.
DougCranston
 
1/ Try putting the js file in the same directory, that will rule out or show a path problem

2/ I've never seen a script tag written with line breaks like you have it. It might be fine but try it this way. The path is as I described above. Also, drop language, it's depreciated.

Code:
<script type=&quot;text/javascript&quot; src=&quot;vldprcrqst.js&quot;></script>

3/ Are there statements in the js file that use relative paths?
 
make sure you do NOT include the <script></script> tags within the .js file itself.


=========================================================
while (!succeed) try();
-jeff
 
gph1 and jemminger,

Thanks for taking the time this holiday weekend.

Will try gph1's solution in the AM once back in the office. (and no #3 relative paths ref'd in the .js file.)

jemminger. Confirmed that the .js file did not have any <script> tags in it. Been known to do those kinds of bone head things, but not this time. Would not have surprised me. In fact after reading your response I was betting I had, but surprised myself that I had not done the whoops.

Appreciate your responses.
DougCranston
 
make sure you don't have any naming conflicts across the various .js files - i.e. all functions and vars need unique names


=========================================================
while (!succeed) try();
-jeff
 
Sounds like naming conflicts. If there were problems loading the external .js you'd get 'Object expected' on submitting. That it submits without tripping the alert in your validation logic argues for the existence of an evil twin
Code:
validcheks()
hijacking the intended validation process.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top