Click to See Complete Forum and Search --> : trouble loading another page.


Kazan
04-27-2003, 11:37 PM
I am having some trouble with the self.location.replace() function. It will not load a page when I use the submit button to check a text and password field.

This is my generic code. I have the onSubmit pass the whole of the form data into the function, and I sort it from there. The names of the fields should be self evident.



function SubCheck(FormData)
{
if(FormData.UName.value!="")
{
if(FormData.Pass.value!="")
{
if(FormData.UName.value!="User1" || FormData.UName.value!="User2")
{
window.location.replace("NotReg.htm")
return true
}
else
{
if(FormData.UName.value="User1")
{
if(FormData.Pass.value="A_Password")
{
self.location.replace("Logged.htm")
return true
}
else
{
self.location.replace("NotLogged.htm")
return true
}
}
else if(FormData.UName.value="User2")
{
if(FormData.Pass.value="A_Password")
{
this.location.replace("Logged.htm")
return true
}
else
{
self.location.replace("NotLogged.htm")
return true
}
}
}
}
else
{
alert("You must enter your password!")
return false
}
}
else
{
alert("You must enter a username!")
return false
}
}



If anyone can offer me some help, I would appreciate it very much. (I realize that the existance of the actuall name and password within the code makes for very poor security, but, it is on a personal server, that only I and a friend use, simply to test out our pages.)

khalidali63
04-28-2003, 07:22 AM
It doesn't look like anything wrong,unless there is some value that might be breaking your code because of relative HTML.
I am sure you know that the useage of replace will load this page in the current location in history,once loaded you can not go back to the previous page using browsers back button,
I'd rather use window.location.href = url,it will load thepage in the current window keeping history entry.
Please post your relative html as well..

Kazan
04-28-2003, 04:16 PM
Here is the relative HTML:


<table width="95%" border="0" cellspacing="1" bgcolor="333333">
<tr>
<td class="Post2" align="center" height=150>
<form name="Login" onSubmit="javascript:SubCheck(this)">
<span style="float: left; margin-left: 5px; margin-top: 5px">User Name: <input name="UName"></span>
<span style="float: right; margin-right: 5px; margin-top: 5px">Password: <input type="password" name="Pass"></span>
<br>
<input type="Submit" value="Login" style="margin-top: 30px" id="Bevel">
</form>
<br>
<span class="small">Not Registered? <a href="Reg.htm">Click here to register.</a></span>
</td>
</tr>
</table>