Javascrip password code

Hey

i have this code:

<a href="page1.htm" onclick="ConfirmPassword( this ); return false;" > Enter </a>

<script type="text/javascript">
<!--
{
        // get the password
        var strPassword = prompt( "Please Enter Password Here" );

       // Go to the password protected page
       window.location.href = "www.domain.com/" + strPassword + "/" + objTargetLink.href;
}
-->
</script>

which only allows people to view my page, if they enter a correct password. i have a few problems with it i am using dw mx 2004.

1. the page loads and then asks for the password so people can see the contents of the page when it asks for the password.
2. the word undifined appears in the password slot, how do i define my password?

any help would be appreciated

thank you

gary

garypyneAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

BustaroomsCommented:
well the undefined thing is solved by this

// get the password
       var strPassword = prompt( "Please Enter Password Here", "" );


the second attribute is the default value for the field

is this the exact code you have on the page?  if so, you fogot to give the function you made a name.  it should be


<script type="text/javascript">
<!--
function ConfirmPassword(objTargetLink){
       // get the password
       var strPassword = prompt( "Please Enter Password Here" );

      // Go to the password protected page
      window.location.href = "www.domain.com/" + strPassword + "/" + objTargetLink.href;
}
-->
</script>
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
garypyneAuthor Commented:
thanks it all woked, but now i dont know how to chnage the pass, where do i enter the passsword i want to use?

ty

gary
0
BustaroomsCommented:
umm, well what you have setup is going to do the following,

user clicks on the link and they will be prompted for a password. they enter that password, and then you send them to the page http://www.domain.com/[whater they typed goes here]/page1.htm

so if i typed "garypyne"  in the prompt, i would be taken to "http://www.domain.com/garypyne/page1.htm"

so, if that was not the right "password" i would get a broken page, if it was right, I would go to a page that works.

This is NOT a good way of doing a password protected site by any means.  In fact, if you are looking to truly password protect your site, Javascript is not your answer, it needs to be client side.
0
Ultimate Tool Kit for Technology Solution Provider

Broken down into practical pointers and step-by-step instructions, the IT Service Excellence Tool Kit delivers expert advice for technology solution providers. Get your free copy now.

garypyneAuthor Commented:
is page1 just an example or does it automatically oipen that one first, if not can u set it to which page it opens first?

ty

gary
0
BustaroomsCommented:
that's in there b/c that's what you had in your code.

i would suggest changing it to

 // Go to the password protected page
      window.location.href = "www.domain.com/" + strPassword + "/"

and if that's the right directory, you'll have the correct index.html page there
0
garypyneAuthor Commented:
ok im so confused right now.

at the moment i have this code

 <a href="page1.htm" onclick="ConfirmPassword( this ); return false;" > Enter</a>

<script type="text/javascript">
<!--
function ConfirmPassword(objTargetLink){
       // get the password
       var strPassword = prompt( "Please Enter Password Here", "");

      // Go to the password protected page
      window.location.href = "http://3xd.recongamer.com/hkrules" + strPassword + "/" + objTargetLink.href;
}
-->
</script>

ok i think this is all correct. this is the website url:

http://3xd.recongamer.com/hkrules

and that is the folder where my protected page is (by the way, theres nothing of importance so im using java cos its supposedly the quickest and easiest :P)

i have a page in there called test.htm

and i want the password to be "hkrules" which is the folder name, therefore th password as well. i inserted this on my website and uploaded it, all it done was display the password i had written in a windows error box, but all it said was the password i ahd eneterd. for example if i entered "pass" as the password the box would show me "pass" and thats it. it did not link me to any pages at all.

is there any chance you could show me exactly what to do.

thank you for all your help so far i really appreciate it

ty

Gary
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
JavaScript

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.