Page 1 of 1

javascript not working when externally linked

Posted: Wed Aug 27, 2008 10:45 am
by queirdo
I'm having a weird problem. I'm using some javascript functions to do client side encryption for a login form. Everything works perfectly when I have the javascript copied out between script tags in the header, but when I do an external link to the file with the exact same code, it doesn't work at all. I've used javascript before and haven't encountered this problem, and i can't seem to figure out what is different in this page that could be interfering. The script is in a file called encrypt.js in the same folder...I literally can copy and paste it between the script tags and it works...it's mostly MD5 encryption functions, and a function for doing CHAP login authentication (I didn't write it, borrowed from an internet tutorial, but I do understand how it works). I have the same problem in Firefox and IE 7, and I've tried changing the order of the attributes or removing some in the script tag but it didn't make a difference.

Can anyone help?

Code: Select all

<?php
// session holds encrypted challenge code
session_start();
$_SESSION['challenge']=md5(rand(1,100000));
?>
 
<html>
<head>
    <title>Login</title>
    <style type="text/css" media="all">@import "css/style.css";</style>
    <script type="text/javascript" language="JavaScript" src="encrypt.js"></script>
</head>
 
<body>
<noscript><p><font color="red">it appears that you have javascript turned off in your browser. 
    You must enable javascript or you won't be able to log in.</font></p></noscript>
     
<form method="post" onSubmit="return doCHAP()" action="login.php">
User ID <input type="text" size="15" name="username" id="username"/><br />
Password <input type="password" size="15" name="pass" id="pass"/><br />
<input type="hidden" name="challenge" id="challenge" />
<input type="submit" name="login" value="Log In" />
</form>
</body>
</html>

Re: javascript not working when externally linked

Posted: Wed Aug 27, 2008 2:06 pm
by kaszu
Are you sure it's in the same folder as the file (assuming your not rewriting url)?

Re: javascript not working when externally linked

Posted: Wed Aug 27, 2008 3:03 pm
by queirdo
Absolutely sure. I've tried it on both my dedicated server and also on my computer, where i can clearly see they are in the same folder. If I type in the url for the javascript file it comes up in the browser where it should be.

Re: javascript not working when externally linked - solved

Posted: Wed Aug 27, 2008 3:22 pm
by queirdo
I figured it out by testing each part of the code to see what made the file fail. It was one line of code that had a <?php ?> tag in it, which i didn't realize because i copied parts of the code from a tutorial and they used external links. it makes sense that the external file wouldn't know what to do with the php part.