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

external js file 2

Status
Not open for further replies.

pantinc

Programmer
Jun 18, 2001
17
0
0
US
I'm having problems using an external .js file to hide password information. What's the proper way to call up a .js file, and once I've done that; is there any special way I have to write the .js file itself?
 
You just have to link to it in the <HEAD> section of your page like this:

<SCRIPT LANGUAGE=&quot;JavaScript&quot; SRC=&quot;jsource.js&quot; TYPE=&quot;text/javascript&quot;></SCRIPT>

There is nothing fancy about the .js file.
Greg.
 
u prolly know this but just makin sure...

be sure to specify the actual folder the .js file is in...
 
how do i write the .js file so that it will work? does it have to be in the same directory as the script? -Sunny *:->*
 
Like riffy says above, it doesn't matter where the .js file is, as long as you specify it's location in the SRC parameter relative to the current page. For example, I have all my .html pages in the root directory on my webspace, and all my .js files in a subdirectory called include, so in my case it looks like this ...

<SCRIPT LANGUAGE=&quot;JavaScript&quot; SRC=&quot;include/jsource.js&quot; TYPE=&quot;text/javascript&quot;></SCRIPT>

If the contents of the .js file are syntactically correct, then it will work. Linking to the .js file externally has essentially the same effect as if you just pasted it's entire contents into the <HEAD> section of your html page.

Greg.
 
ok this is the .js file for some reason, it's not working...
is this all i have to do with it? besides change the usernames and passwords and window.location?
<SCRIPT LANGUAGE=&quot;JavaScript&quot;>

function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();
var password=document.login.password.value;
password=password.toLowerCase();
if (username==&quot;member1&quot;&&password==&quot;password1&quot;)
{window.location=&quot;page1.html&quot;; done=1;}
if (username==&quot;member2&quot;&&password==&quot;password2&quot;)
{window.location=&quot;page2.html&quot;; done=1;}
if (username==&quot;member3&quot;&&password==&quot;password3&quot;)
{window.location=&quot;page3.html&quot;; done=1;}
if (done==0) {alert(&quot;Try again!!&quot;);}}
</SCRIPT>
-Sunny *:->*
 
First of all, take out all the html <SCRIPT> tags. They aren't needed in the include file. It should just contain pure javascript. Then test it again. If it still doesn't work, other things to look at may be;
- Make sure there's a form called login
- Make sure there are fields called username and password

There may be an issue with having javascript variables with the same name as form elements. I'm not sure on that one.

Hope this helps a bit.

Greg.
 
Thanks so much for the help! It works now. I know it was a simple problem, but being new to this, its difficult to find people willing to help. -Sunny *:->*
 
No worries Sunny. There's always someone here to point you in the right direction :)

Greg.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top