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="JavaScript" SRC="jsource.js" TYPE="text/javascript"></SCRIPT>
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="JavaScript" SRC="include/jsource.js" TYPE="text/javascript"></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.
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="JavaScript">
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=="member1"&&password=="password1"
{window.location="page1.html"; done=1;}
if (username=="member2"&&password=="password2"
{window.location="page2.html"; done=1;}
if (username=="member3"&&password=="password3"
{window.location="page3.html"; done=1;}
if (done==0) {alert("Try again!!"}}
</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.
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 *:->*
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.