Click to See Complete Forum and Search --> : need a tweak


Tasmanian Devil
06-22-2003, 11:15 AM
How do I make this script , when submitted, goes to a new page? I still need it to popup the window like it is in the script now. Just the first window to change to a different url?

<html>
<head>
<title>Log In</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<SCRIPT LANGUAGE="JavaScript">
var expDays = 999999;

var exp = new Date();

exp.setTime(exp.getTime() + (expDays*24*60*60*1000));

function getCookieVal (offset) {

var endstr = document.cookie.indexOf (";", offset);

if (endstr == -1) { endstr = document.cookie.length; }

return unescape(document.cookie.substring(offset, endstr));

}

function GetCookie (name) {

var arg = name + "=";

var alen = arg.length;

var clen = document.cookie.length;

var i = 0;

while (i < clen) {

var j = i + alen;

if (document.cookie.substring(i, j) == arg) return getCookieVal (j);

i = document.cookie.indexOf(" ", i) + 1;

if (i == 0) break;

}

return null;

}

function SetCookie (name, value) {

var argv = SetCookie.arguments;

var argc = SetCookie.arguments.length;

var expires = (argc > 2) ? argv[2] : null;

var path = (argc > 3) ? argv[3] : null;

var domain = (argc > 4) ? argv[4] : null;

var secure = (argc > 5) ? argv[5] : false;

document.cookie = name + "=" + escape (value) +

((expires == null) ? "" : ("; expires=" + expires.toGMTString())) +

((path == null) ? "" : ("; path=" + path)) +

((domain == null) ? "" : ("; domain=" + domain)) +

((secure == true) ? "; secure" : "");

}

function cookieForms() {

var mode = cookieForms.arguments[0];

for(f=1; f<cookieForms.arguments.length; f++) {

formName = cookieForms.arguments[f];

if(mode == 'open') {

cookieValue = GetCookie('saved_'+formName);

if(cookieValue != null) {

var cookieArray = cookieValue.split('#cf#');

if(cookieArray.length == document[formName].elements.length) {

for(i=0; i<document[formName].elements.length; i++) {

if(cookieArray[i].substring(0,6) == 'select') { document[formName].elements[i].options.selectedIndex = cookieArray[i].substring(7, cookieArray[i].length-1); }

else if((cookieArray[i] == 'cbtrue') || (cookieArray[i] == 'rbtrue')) { document[formName].elements[i].checked = true; }

else if((cookieArray[i] == 'cbfalse') || (cookieArray[i] == 'rbfalse')) { document[formName].elements[i].checked = false; }

else { document[formName].elements[i].value = (cookieArray[i]) ? cookieArray[i] : ''; }

}

}

}

}

if(mode == 'save') {

cookieValue = '';

for(i=0; i<document[formName].elements.length; i++) {

fieldType = document[formName].elements[i].type;

if(fieldType == 'password') { passValue = ''; }

else if(fieldType == 'checkbox') { passValue = 'cb'+document[formName].elements[i].checked; }

else if(fieldType == 'radio') { passValue = 'rb'+document[formName].elements[i].checked; }

else if(fieldType == 'select-one') { passValue = 'select'+document[formName].elements[i].options.selectedIndex; }

else { passValue = document[formName].elements[i].value; }

cookieValue = cookieValue + passValue + '#cf#';

}

cookieValue = cookieValue.substring(0, cookieValue.length-4); // Remove last delimiter

SetCookie('saved_'+formName, cookieValue, exp);

}

}

}
</script>

<SCRIPT LANGUAGE="JavaScript">
function Login(){
var done=0;
var username=document.login.username.value;
username=username.toLowerCase();

if (username=="mbouali") { window.open('http:\/\/foxvalleynews.com/Mohamed Bouali/Mohamed Bouali.htm','','resizeable=yes,scrollbars=yes,menubar=no,width='+screen.width+',height='+screen.heig ht+',left=0,top=0');window.close(); done=1; }

if (username=="new user") { window.open('http:\/\/foxvalleynews.com/new user login.html','','resizeable=yes,scrollbars=yes,menubar=no,width='+screen.width+',height='+screen.heig ht+',left=0,top=0');window.close(); done=1; }

if (done==0) { alert("Invalid Username!"); }
}
</SCRIPT>

<SCRIPT LANGUAGE="JavaScript">
function popUp(URL) {
day = new Date();
id = day.getTime();
eval("page" + id + " = window.open(URL, '" + id + "', 'toolbar=0,scrollbars=1,location=0,statusbar=0,menubar=0,resizable=0,width=900,height=900,left = 300,top = 250');");
}
</script>
</head>

<body bgcolor="#FFFFFF" text="#000000" background="http://foxvalleynews.com/clouds.jpg" body onload="cookieForms('open', 'login')" onunload="cookieForms('save', 'login')">
<form name=login>
<table width=452 border=0 cellpadding=0 align="left">
<tr>
<td colspan=3 height="99">
<center>
<font size="+2"><b><font size="+5" face="Times New Roman, Times, serif">Please
Login</font><br>
</b></font><br>
<font face="Geneva, Arial, Helvetica, san-serif" size="3">If you are
a new user, just press the login button<br>
otherwise type in your username and then press the login button.</font>
</center>
</td>
</tr>
<br>
<tr>
<td width="75">Username:</td>
<td width="130">
<input type=text name=username value="new user">
</td>
<td width="239">&nbsp;</td>
</tr>
<tr>
<td align=center width="75">&nbsp; </td>
<td align=center>
<div align="center">
<input type=button value="Login!" onClick="Login()" name="button">
</div>
</td>
</tr>
</table>
</form>
</body>
</html>

Thanks
Devil

David Harrison
06-22-2003, 11:28 AM
Use:
location.href="whatever.html";

Tasmanian Devil
06-22-2003, 11:31 AM
where do you put that?
Thanks
Devil

David Harrison
06-22-2003, 11:33 AM
Ok, gimme a minute to browse through your code.

David Harrison
06-22-2003, 11:41 AM
Well you could just stick it just before the end of your login function.

Also, in the following snippet of code:

if (username=="mbouali") { ... }
if (username=="new user") { ... }

you should really use

if (username=="mbouali") { ... }
else if (username=="new user") { ... }

I'm not 100% sure about the location.href because I haven't tried it, your script didn't work when I tried it (Using Win 98 se & IE 5.x)

Tasmanian Devil
06-22-2003, 11:42 AM
I have win 98 first and with IE5.5 it works there

David Harrison
06-22-2003, 11:45 AM
Well upload a .txt of your source code as an attachment to a message and I'll convert it to .html and try that.