/    Sign up×
Community /Pin to ProfileBookmark

Password validation

Hello everyone.

I am trying to have a page where a user enters a password in an input box to view information on another page. I only need it to be one password, and if they enter the correct password then they are allowed to go to the next page to see the information. I know that the user could just go into the code and see the password but they could just as easily get a flyer from the organization this is for and get the password as well. I’m just trying to make it happen. Thanks to everyone who can help me.

lonogod

to post a comment
JavaScript

9 Comments(s)

Copy linkTweet thisAlerts:
@JPnycDec 28.2005 — put this in the document head, call the validate() function onsubmit of your form tag, and name the pasword textbox "password". Replace myPassword with whatever you want your password to be.

<script type="text/javascript">

<!--

function validate() {

var pw = document.forms[0].password.value;

if(pw == "myPassword") {

window.location.href = "newPage.htm"

}}

//-->

</script>
Copy linkTweet thisAlerts:
@lonogodauthorDec 28.2005 — Hi JPnyc. Thanks for the quick reply. What do I put for the form action?

lonogod
Copy linkTweet thisAlerts:
@JPnycDec 28.2005 — You can leave the value blank (action=""), since there's nothing being done with it. In fact you wouldn't even need a form tag for this, if not for some older browsers not showing form elements without a form tag. You could just call the function onclick of the button
Copy linkTweet thisAlerts:
@lonogodauthorDec 28.2005 — Hey JPnyc. Thanks again, but I must be doing something wrong because it's not working for me. Here's what I put:&lt;html&gt;

&lt;head&gt;

&lt;script type="text/javascript"&gt;
&lt;!--
function validate() {
var pw = document.forms[0].password.value;

if(pw == "whatever") {
window.location.href = "http://www.yahoo.com/"
}}

//--&gt;
&lt;/script&gt;

&lt;/head&gt;

&lt;body&gt;

&lt;form action="" onsubmit="validate()"&gt;

&lt;input type="text" name="password"&gt;&lt;br&gt;&lt;br&gt;&lt;input type="submit"&gt;

&lt;/form&gt;

&lt;/body&gt;

&lt;/html&gt;
Can you tell me what I'm doing wrong? Thanks again.

lonogod
Copy linkTweet thisAlerts:
@CrazyMerlinDec 28.2005 — change window.location to document.location
Copy linkTweet thisAlerts:
@lonogodauthorDec 28.2005 — Hey CrazyMerlin. That gave me the same result. The page just refreshes.
Copy linkTweet thisAlerts:
@A1ien51Dec 28.2005 — change window.location to document.location[/QUOTE]

The correct syntax is window.location....so scratch that thought

onsubmit="validate(); return false;">

You need to return false from keeping the page from submitting.

Eric
Copy linkTweet thisAlerts:
@lonogodauthorDec 28.2005 — Thank you A1ien51. It works perfectly.

lonogod
×

Success!

Help @lonogod spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.14,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...