View Single Post
  #1 (permalink)  
Old 11-21-07, 11:30 PM
semendemon semendemon is offline
New Member
 
Join Date: Nov 2007
Posts: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Help Needed Urgently with JS Login Script!

Hey guys, I am having a problem with a simple login Javascript page that I made, which works fine and loads its "success page" (which is the page that it goes to when the login entered is correct) perfectly on my computer. However, when I upload it, the script runs fine up to the point where the login is checked for validity (it even displays an error dialog when your login is incorrect and you press login, so the button is working somewhat), but it DOES NOT go to the success page it is supposed to. It just stops. I checked the script and could not a find a "break" in the operation that could be causing it (again, it works fine on my computer). What do you guys think could be the problem? My domain host (just in case it might be the cause of the problem) is GeoCities (yes, I'm a broke student, lol).

A little about the overall website: I have made a website for my school project (which is starting a new business). The website is www.txtmobility.2ya.com if you guys want to test the hosted login page out for yourselves. Just go under the login menu and select one of the pages. They are all using the same scripts as the BusinessLogin script that is shown below.

Thanks A LOT for your help in advance, guys.

BusinessLogin.html Code:

HTML Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<!-- DW6 -->
<head>
<script type="text/javascript" src="flashobject.js"></script>
<script type="text/javascript" src="BusinessLogin.js"></script>
<!-- Copyright 2005 Macromedia, Inc. All rights reserved. -->
<title>TXT® Mobility: TXT® Business Registration</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<link rel="stylesheet" href="mm_lodging1.css" type="text/css" />
</head>
<body bgcolor="#999966">
<table width="100%" border="0" cellspacing="0" cellpadding="0">
	<tr>
	<td width="15" nowrap="nowrap">&nbsp;</td>
	<td height="60" colspan="2" class="logo" nowrap="nowrap">TXT<sup>®</sup> Mobility</td>
	<td width="311">&nbsp;</td>
  </tr>

	<tr bgcolor="#ffffff">
	<td colspan="4"><img src="mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
	</tr>

	<tr bgcolor="#a4c2c2">
	<td width="15" nowrap="nowrap">&nbsp;</td>
	<td height="36" id="navigation" class="navText">
    <div id="color_id" >123 Flash Menu Placeholder.</div>
	<script type="text/javascript">
var fo = new FlashObject("MenuBar.swf","color","704","100","6","#FFFFFF");
    fo.addParam("menu","false");
    fo.addParam("quality","best");
    fo.addParam("scale","noscale");
    fo.addParam("salign","LT");
    fo.addParam("wmode", "transparent");
    fo.write("color_id");
</script></td>
	<td>&nbsp;</td>
	<td width="311">&nbsp;</td>
  </tr>

	<tr bgcolor="#ffffff">
	<td colspan="4"><img src="mm_spacer.gif" alt="" width="1" height="1" border="0" /></td>
	</tr>

	<tr bgcolor="#ffffff">
	<td valign="top" width="15"><img src="mm_spacer.gif" alt="" width="15" height="1" border="0" /></td>
	<td valign="top" width="672"><img src="mm_spacer.gif" alt="" width="35" height="1" border="0" />
	  <table width="100%" height="280" cellpadding="3" cellspacing="0">
        <tr>
          <td width="100%" height="40"><h2>TXT<sup>®</sup> Business<sup></sup> Login</h2></td>
        </tr>
        <tr>
          <td align="left"><script language="JavaScript">
  BuildPanel();
 </script></td>
        </tr>
      </table></td>
	<td width="4" valign="top"><br />
	  &nbsp;<br />	</td>
	<td>&nbsp;</td>
	</tr>

	<tr>
	<td width="15">&nbsp;</td>
    <td width="672">&nbsp;</td>
    <td width="4">&nbsp;</td>
	<td width="311">&nbsp;</td>
  </tr>
</table>
</body>
</html>
BusinessLogin.js Code:

Javascript Code:
  1. //----------------------------------------------------------------
  2. //  Usernames, Passwords & User Pages - These require configuration.
  3. //----------------------------------------------------------------
  4. var successpage = "BusinessOnline.html"; // The page users go to after login, if they have no personal page.
  5. var loginpage = "BusinessLogin.html"; //Change this to the page the login panel is on.
  6.  
  7. var imgSubmit = ""; //Change to the path to your login image,if you don't want the standard button, otherwise do not change.
  8. var imgReset = ""//Change to the path to your reset image,if you don't want the standard button, otherwise do not change.
  9.  
  10. var users = new Array();
  11.  
  12. users[0] = new Array("schulich","class2011","BusinessOnline.html"); // Change these two entries to valid logins.
  13. // Add addtional logins, straight after these, as
  14. // required, followig the same format. Increment the
  15. // numbers in the square brackets, in new each one. Note:
  16. // the 3rd parameter is the the page that user goes to
  17. // after successful login. Ensure the paths are correct.
  18.                                                            // Make this "" if user has no personal page.
  19. //----------------------------------------------------------------
  20. //  Login Functions
  21. //----------------------------------------------------------------
  22. function login(username,password){
  23.  var member = null;
  24.  var loggedin = 0;
  25.  var members = users.length;
  26.  for(x=0;x<members && !loggedin; x++){
  27.  if((username==users[x][0])&&(password==users[x][1])){
  28.     loggedin = 1;
  29.     member = x;
  30.     break; // User validated, terminate the for loop.
  31.    }
  32.  }
  33.  
  34.  if(loggedin==1){
  35.   if(users[member][2] != "") {
  36.    successpage = users[member][2];
  37.   }
  38.   setCookie("login",1);
  39.   if (top.location.href != location.href){
  40.    location.href = successpage;           
  41.   }else{
  42.    top.location.href = successpage; 
  43.   }
  44.  }else{
  45.   alert('User name or password is incorrect. Please try again.');
  46.  } 
  47. }
  48.  
  49. function logout() {
  50.  deleteCookie("login");
  51.  if (top.location.href != location.href){
  52.   location.href = loginpage;           
  53.  }else{
  54.   top.location.href = loginpage; 
  55.  }
  56. }
  57.  
  58. //----------------------------------------------------------------
  59. // Cookie Handler
  60. //----------------------------------------------------------------
  61. var ckTemp = document.cookie;
  62.  
  63. function setCookie(name, value) {
  64.  if (value != null && value != "")
  65.   document.cookie=name + "=" + escape(value) + ";";
  66.  ckTemp = document.cookie;
  67.  }
  68.  
  69. function deleteCookie(name) {
  70.   if (getCookie(name)) {
  71.     document.cookie = name + "=" +
  72.     "; expires=Thu, 01-Jan-70 00:00:01 GMT";
  73.   }
  74. }
  75.  
  76. function getCookie(name) {
  77.  var index = ckTemp.indexOf(name + "=");
  78.  if(index == -1) return null;
  79.   index = ckTemp.indexOf("=", index) + 1;
  80.  var endstr = ckTemp.indexOf(";", index);
  81.  if (endstr == -1) endstr = ckTemp.length;
  82.  return unescape(ckTemp.substring(index, endstr));
  83.  }
  84.  
  85. function checkCookie() {
  86.  var temp = getCookie("login");
  87.  if(!temp==1) {
  88.   alert('You must be logged in to view this page.');
  89.   if(top.location.href != location.href){
  90.    location.href = loginpage;           
  91.   }else{
  92.    top.location.href = loginpage; 
  93.   }
  94.  }
  95. }
  96.  
  97. //----------------------------------------------------------------
  98. // Login Panel
  99. //----------------------------------------------------------------
  100.  
  101. function BuildPanel() {
  102. document.write('<form name="logon"><table align="left" border="0"><tr><td align="right">');
  103. document.write('<small><font face="Verdana">Username:</font></small></td>');
  104. document.write('<td><small><font face="Verdana"><input type="text" name="username" size="20"></font></small></td></tr>');
  105. document.write('<tr><td align="right"><small><font face="Verdana">Password:</font></small></td>');
  106. document.write('<td><small><font face="Verdana"><input type="password" name="password" size="20"></font></small></td></tr>');
  107. if(imgSubmit == ""){
  108.  document.write('<tr><td align="center" colspan="2"><p><input type="button" value="Login" name="Logon" onclick="login(username.value,password.value)">');
  109. } else {
  110.  document.write('<tr><td align="center" colspan="2"><p><input type="image" src="'+imgSubmit+'" name="Logon" onclick="login(username.value,password.value)">');
  111. }
  112. if(imgReset == ""){
  113.  document.write('<input type="reset" value="Reset" name="Reset">');
  114. } else {
  115.  document.write('<input type="image" src="'+imgReset+'" name="Reset" onclick="logon.reset();">');
  116. }
  117. document.write('</p></td></tr></table></form>');
  118. }

Last edited by UnrealEd; 11-22-07 at 05:20 AM. Reason: please use the proper syntax highlighter
Reply With Quote