/    Sign up×
Community /Pin to ProfileBookmark

Problem with location.href

function callme(form)
{
if(document.forms[0].elements[1].value==”ajax” && document.forms[0].elements[2].value==”ajax”)
{
window.location.href = “home.jsp”
//document.location.href=”http://localhos:8080/jsp-examples/tech_fb/retrieve1.jsp“;
}
else
{
alert(“——–“);
}
}

I need the above code to check username and password. If they are correct then it goes to home.jsp otherwise it shows an alert box. Here the location.href wont work. Why it happens so? I have also tried window.open..it works. but i need a page to be open by overwrite the existing window and not a new one. How can i do this . Any help regard this would be appreciated…

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@KorMay 30.2008 — collection's (and array's) index starts in javascript from 0. If your fields are the first two form's elements, should be:
<i>
</i>if(document.forms[0].elements[[COLOR="Blue"]0[/COLOR]].value=="ajax" &amp;&amp; document.forms[0].elements[[COLOR="Blue"]1[/COLOR]].value=="ajax")

But you should not use javascript for jobs related with passwords. Javascript is a client-side language, everyone can see the code, thus is totally insecure.
Copy linkTweet thisAlerts:
@Declan1991May 30.2008 — JavaScript is client-side (which is what Kor meant to write) and thus is completely insecure for password protection.

The reason why document.location.href doesn't work is because it's window.location.href or just simply location.href if you're not working with frames or pop-ups.

And BTW, there is a method of encrypting the page using JavaScript, and using the password as part of the decrypting method. That is not password protection, and if you try it on any reasonably sized page, it will cause the users browser to crash most likely. The only way to achieve true password protection with any flexibility in the password is to use something server-side.
×

Success!

Help @rajkumar001 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...