Custom validation not working when Javascript moved to external file

A

Alan Silver

Hello,

I am writing a page that makes use of a lot of custom validators. So
far, all the custom client-side validation code has been added in the
<head> tag of the page, but I decided to move it out to an external file
to keep this file cleaner. Trouble is that it now doesn't get called at
all.

I have the following line in the <head> of the page...

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

I know the reference is right as a) the file is there and b) VWD gave me
the file name in a drop-down when I typed the "src" attribute. Despite
this, the code in there just doesn't get called. It works fine when the
code is inline in the page itself.

Anyone any ideas? TIA
 
A

Alan Silver

Anyone any ideas? TIA

I have!! I found out the problem, it was due to the way I was getting
element names in the Javascript. As I am using Master pages, the IDs of
the elements is not known at design time, so I have to do something
like...

myvalue = document.forms[0].<%= txtCustomerNumber.ClientID %>.value;

which works fine when the Javascript is in the .aspx file, but (rather
obviously) fails when it is moved into an external .js file.

So, it looks like this can't be done. Anyone any ideas? TIA
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,743
Messages
2,569,478
Members
44,898
Latest member
BlairH7607

Latest Threads

Top