1 Javascript - LogIn form Thu May 24, 2012 3:28 am
Mr.Joker
Mr. WebArtz
Hello members of WebArtz forum, I am Mr.Joker and today I will show you how to make a simple login page. I must tell you that you should not use javascript for LogIn EVER, EVER, EVER, EVER AND NEVER. This is only like valiadation form not login because everyone can see from source code the username and password you enter. For Loging in we use PHP. Ok here is code:
This is really simple. You allready know how forms and elements function with javascript, and you also know advanced else if statement. We have Username and Password field. Now, when someone want to login we need to make a function that happen. So, we create two variables to take values from fields as I explained in last tutorial, and now we make a statement. With first condition I say if userName is equal to "WebArtz" and password is equal to "I love it" then javascript will redirect me to WebArtz. Thats why I used:
All questions you can ask in this thread.
- Code:
<html>
<head>
<title>Javascript - Forms</title>
<script type="text/javascript">
function test() {
var userName = document.Form1.Element1.value;
var password = document.Form1.Element2.value;
if ((userName=="WebArtz") && (password=="I love it")) {
window.open("http://www.webartzforum.com/");
} else {
window.open("http://www.google.com")
}
}
</script>
</head>
<body>
<form name="Form1">
<span>Enter Username</span>
<input type="text" name="Element1"/>
<span>Enter password:</span>
<input type="text" name="Element2"/>
<input type="button" value="Click me" onClick="test()"/>
</form>
</body>
</html>
This is really simple. You allready know how forms and elements function with javascript, and you also know advanced else if statement. We have Username and Password field. Now, when someone want to login we need to make a function that happen. So, we create two variables to take values from fields as I explained in last tutorial, and now we make a statement. With first condition I say if userName is equal to "WebArtz" and password is equal to "I love it" then javascript will redirect me to WebArtz. Thats why I used:
- Code:
window.open("URL")
All questions you can ask in this thread.