Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

code issues!!

Status
Not open for further replies.

iLy54

Programmer
Sep 5, 2002
33
0
0
ZA
whats wrong with this code?

<script language=&quot;javascript&quot;>
function checklogin(x)
{
if ((x.id.value != &quot;peaches&quot;)||(x.pass.value !=&quot;cream&quot;))
{
alert(&quot;Invalid Login&quot;);
return false;
}
else
window.location.replace('peaches&cream.html');
}
</script>

the problem i hav with this code is that when you enter the correct login and the correct password it doesnt redirect you to the required page.it just refreshes the page.
can anyone advise me on a solution?
thanx
-Mon3y is the r00t of all evil and every man needs roots-
 
First of all we don't know what x is and second you cannot use the & in a url unless you have querystring variable(s).
Can you try this?

<script language=&quot;javascript&quot;>
function checklogin(x)
{
alert(&quot;I know my id value is: &quot; + x.id.value);
alert(&quot;I know my pass value is: &quot; + x.pass.value);
alert(&quot;I know that checking both these values is case sensitive&quot;);
if ((x.id.value != &quot;peaches&quot;)||(x.pass.value !=&quot;cream&quot;))
{
alert(&quot;Invalid Login&quot;);
return false;
}
else
alert(&quot;ok it should go to another url now&quot;);
window.location.replace('peaches&cream.html');
}
</script>

 
iv tried everything and still hav the same problem. i made a mistake by puting the & in my post. my script doesnt hav it. i even pasted your code above and it stil gives the same problem.
here's how i use it:

<form>
<p>User ID:<input type=&quot;text&quot; name=&quot;id&quot;></p>
<p>Password:<input type=&quot;password&quot; name=&quot;pass&quot;></p>
<p align=&quot;center&quot;><input type=&quot;image&quot; name=&quot;submit&quot; src=&quot;submit.gif&quot; onClick=&quot;checklogin(this.form)&quot;></p>
</form>

i think the problem is with the window.location.replace function. when i use window.open() the validation script works perfectly. -Mon3y is the r00t of all evil and every man needs roots-
 
When you click the image the form is submitted for server side processing. Because the form doesn't have an action=... property the form is submitted to its own url (refreshed).

try this:
<form>
<p>User ID:<input type=&quot;text&quot; name=&quot;id&quot;></p>
<p>Password:<input type=&quot;password&quot; name=&quot;pass&quot;></p>
<p align=&quot;center&quot;><img name=&quot;submit&quot; src=&quot;submit.gif&quot; onClick=&quot;checklogin(this.form)&quot;></p>
</form>

 
when i try what you suggested it gives me an error saying &quot;id&quot; is not and object. this error comes from the script. if the form is submitted for server side processing then why would window.open() work and not window.location.replace?
all i want to do is password protect a certain part of my site where only the password &quot;cream&quot; for ex will get you access to it. -Mon3y is the r00t of all evil and every man needs roots-
 
Put an alert on the window.onload and you see that window.open allso reloads the parent window.
Input type submit submits the form why do you think it's called input type submit??
The reason why id is not working is because you are passing this.form with the onclick event of the img object, the img object is not part of the form.
Try using document.getElementById('id') or give the form an id and use myform.id.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top