By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,568 Members | 1,276 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,568 IT Pros & Developers. It's quick & easy.

Need a little help here... (dont we all?) i need to refrence a var in two scripts....

eragon
100+
P: 431
I am making a password script, i have most of it done, ill show you, but i hit a brick wall.... lol, I have it so when you log in it takes you to your main page, that works, but when you enter the wrong info, it's supposed to say "Invalid Username or Password" below the login boxes. (Using the document.write command), but to do this, i need to refrence the main script to get the yes or no if they logged in right.... i need help.... im using inernet explorer v6.0, heres my script:

This is my external .js file (name is pass.js):

Expand|Select|Wrap|Line Numbers
  1. <!-- Begin
  2. function Login() {
  3. var error="No Errors";
  4. var done=0;
  5. var username=document.login.username.value;
  6. username=username.toLowerCase();
  7. var password=document.login.password.value;
  8. password=password.toLowerCase();
  9. //User info//
  10. if (username=="eragon" && password=="password") { window.location="pages/eragon.htm"; done=1; }
  11. //End User Info//
  12. if (done==0) { error="Incorrect Username or Password"; }
  13. }
  14. // End -->
Ok, that was my external .js file, now heres my web page sorce code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>login</title>
  4. <script language="javascript" src="pass.js">
  5. </head>
  6. <body>
  7. <form name="login">
  8. <input type="text" name="username">
  9. <input type="password" name="password">
  10. <input type="button" value="login" onClick="login()">
  11. </form>
  12. <!-- This is the part i need help with: -->
  13. <script language="Javascript">{ document.write (error);  }</script>
  14. </body>
  15. </html>
So, you saw my scripts, i would appreciate it if you test them, and tell me anything that is wrong.... thanks much, nice people...


Yours thankfully,

Eragon Eisert
Mar 27 '07 #1
Share this Question
Share on Google+
5 Replies


10K+
P: 13,264
I am making a password script, i have most of it done, ill show you, but i hit a brick wall.... lol, I have it so when you log in it takes you to your main page, that works, but when you enter the wrong info, it's supposed to say "Invalid Username or Password" below the login boxes. (Using the document.write command), but to do this, i need to refrence the main script to get the yes or no if they logged in right.... i need help.... im using inernet explorer v6.0, heres my script:

This is my external .js file (name is pass.js):

Expand|Select|Wrap|Line Numbers
  1. <!-- Begin
  2. function Login() {
  3. var error="No Errors";
  4. var done=0;
  5. var username=document.login.username.value;
  6. username=username.toLowerCase();
  7. var password=document.login.password.value;
  8. password=password.toLowerCase();
  9. //User info//
  10. if (username=="eragon" && password=="password") { window.location="pages/eragon.htm"; done=1; }
  11. //End User Info//
  12. if (done==0) { error="Incorrect Username or Password"; }
  13. }
  14. // End -->
Ok, that was my external .js file, now heres my web page sorce code:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>login</title>
  4. <script language="javascript" src="pass.js">
  5. </head>
  6. <body>
  7. <form name="login">
  8. <input type="text" name="username">
  9. <input type="password" name="password">
  10. <input type="button" value="login" onClick="login()">
  11. </form>
  12. <!-- This is the part i need help with: -->
  13. <script language="Javascript">{ document.write (error); }</script>
  14. </body>
  15. </html>
So, you saw my scripts, i would appreciate it if you test them, and tell me anything that is wrong.... thanks much, nice people...


Yours thankfully,

Eragon Eisert
Java != Javascript.

Moved to javascript forum.
Mar 27 '07 #2

acoder
Expert Mod 15k+
P: 16,027
You can't write to the page using document.write() after the page has loaded.

Have a div or a span on the page:
Expand|Select|Wrap|Line Numbers
  1. <div id="errors"></div>
then in your login function at the end:
Expand|Select|Wrap|Line Numbers
  1. document.getElementById("errors").innerHTML=error;
Also, the case must be the same for the function names - you can't use login and Login interchangeably.
Mar 27 '07 #3

eragon
100+
P: 431
it works great! my internet was down so i couldnt post right away, but i tried the script and it works great... just one more question... how do i get the error to only appear if the information is unvalid. I need this because the error message appears every time while the next page is loading. Thank you all for your help!
Apr 9 '07 #4

acoder
Expert Mod 15k+
P: 16,027
When you run your login function, if there are no errors, set the errors variable to an empty string. Then set the div to remove the error message.
Apr 10 '07 #5

eragon
100+
P: 431
i got it all working, thanks... i have another topic i need help with, look for my other thread called "Simple edit... or is it? Help Me!!!" and look at the description...
May 23 '07 #6

Post your reply

Sign in to post your reply or Sign up for a free account.