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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Need to password protect a page.

Status
Not open for further replies.

Cadwalader

IS-IT--Management
Joined
Feb 12, 2002
Messages
297
Location
US
Hello...

I need to password protect one page. It's not a super high security issue, so javascript can do it.

This is what I have so far,

<SCRIPT LANGUAGE=&quot;javascript&quot;>

var getin = prompt(&quot;What is the password?&quot;,&quot;&quot;)
if (getin==&quot;peppermint&quot;)
{
alert('You got it right!')
location.href='laws.html'
}
else
{
if (getin==&quot;null&quot;)
{location.href='nope.html'}
else
if (getin!=&quot;peppermint&quot;)
{location.href='nope.html'}
}
</SCRIPT>

But I don't want that alert in there, and when I take it out, it gets stuck in a loop. You have to enter the password twice, and then you get the error page. Can anyone help? I am so lost...:-( Hope I was of some help...
--OR--
Thanks for the help...
--Rich

 
from the way I'm reading it all you really need is
var getin = prompt(&quot;What is the password?&quot;,&quot;&quot;)
if (getin==&quot;peppermint&quot;)
{
location.href='laws.html'
}
else
{
location.href='nope.html'
} A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Pulling hair out now...

it's looping...no matter how many times you type in the password correctly, it still wants a password...you never get to the page it's protecting.

The error page is showing up great though...anyway, here is the original code as copied from another code-help site...

<SCRIPT LANGUAGE=&quot;javascript&quot;>

var getin = prompt(&quot;What is the password?&quot;,&quot;&quot;)
if (getin==&quot;peppermint&quot;)
{
alert('You got it! In you go...')
location.href='scripttip73correct.html'
}
else
{
if (getin==&quot;null&quot;)
{location.href='nope2.,html'}
else
if (getin!=&quot;peppermint&quot;)
{location.href='nope.html'}
}
</SCRIPT>

All I want to modify is so that there is no alert messege...when I do that, it loops.

Thanks for the help...
Hope I was of some help...
--OR--
Thanks for the help...
--Rich

 
I can't get it to do anything that resembles a loop but there is a typo in there

if (getin==&quot;null&quot;)
{location.href='nope2.,html'}

see the quote
A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
yeah, I see it...with it, with out it, it doesn't matter. It's running like a loop. I even clear the browser history, and tmp files, and still get a loop.


this is turning into a nightmare...
Hope I was of some help...
--OR--
Thanks for the help...
--Rich

 
well first the [rompt will never = null but as is null should not be surounded by &quot; &quot;

second clean it up. All the else's are not needed.
var getin = prompt(&quot;What is the password?&quot;,&quot;&quot;);
alert(getin);
if (getin==&quot;peppermint&quot;) {
alert('You got it! In you go...');
location.href='scripttip73correct.html';
}
if (getin == null) { //should be ==&quot;&quot;
location.href='nope2.html';
}
if (getin!=&quot;peppermint&quot;) {
location.href='nope.html';
}

As before if you really want this to direct to nope2 EVER you need to state ==&quot;&quot; or you will never get there. This works fine on IE5.5 NT
what bowser are you running it on A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Moron of the day announcement!!!!


That script...does it go on the page that you want protected, or does it go on the pages that lead to the page you want protected? Hope I was of some help...
--OR--
Thanks for the help...
--Rich

 
I'm assuming this was on a page that leads to others

I hope anyhow A language that doesn't affect the way you think about programming is not worth knowing.
admin@onpntwebdesigns.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top