Custom validation not working when Javascript moved to external file

  • Thread starter Thread starter Alan Silver
  • Start date Start date
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
 
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
 
Back
Top