Hey! I got a little problem with my websites login page what I started making when I try to run a function in onClick section of button I have to click it two times that the effect comes? If I put the code straight into the onClick it works properly I have no idea. I am really noob in JS as I haven't done it much, so sorry if this is stupid. You can see live demo here about the bug http://breakpoint.no-ip.org here is the HTML code which bugs
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to breakpoint - Login</title>
<link href="style.css" type="text/css" rel="stylesheet" />
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript">
function checkLogin()
{
Effect.BlindDown('error'); return false;
}
function replacePass(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id', 'password');
obj.parentNode.replaceChild(newO,obj);
newO.focus();
}
function replaceName(obj){
if(obj.value == "ACCOUNT NAME")
{
var newO=document.createElement('input');
newO.setAttribute('type','text');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id', 'password');
obj.parentNode.replaceChild(newO,obj);
newO.focus();
}
}
</script>
</head>
<body>
<div id="logindiv">
<img src="images/welcome.png" />
<div id="error" style="display:none; width:25%; height:40px; margin-left:39%; margin-right:auto; font-size:140%; background:#F33;
height:30px;
font-weight:bold;
color:#000;
display:none;
background-color:#F30;">
Incorrect login!
</div>
<form action="#">
<p><label for="name">Name</label> <input type="text" id="name" value="ACCOUNT NAME" onfocus="replaceName(this)" /></p>
<p><label for="password">E-mail</label> <input type="text" id="password" value="PASSWORD" onfocus="replacePass(this)" />
<p> <input type="image" src="images/login2.png" id="submit" onclick="checkLogin()" />
</form>
</div>
</body>
</html>
This works
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Welcome to breakpoint - Login</title>
<link href="style.css" type="text/css" rel="stylesheet" />
<script src="javascripts/prototype.js" type="text/javascript"></script>
<script src="javascripts/scriptaculous.js" type="text/javascript"></script>
<script type="text/javascript">
function checkLogin()
{
Effect.BlindDown('error'); return false;
}
function replacePass(obj){
var newO=document.createElement('input');
newO.setAttribute('type','password');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id', 'password');
obj.parentNode.replaceChild(newO,obj);
newO.focus();
}
function replaceName(obj){
if(obj.value == "ACCOUNT NAME")
{
var newO=document.createElement('input');
newO.setAttribute('type','text');
newO.setAttribute('name',obj.getAttribute('name'));
newO.setAttribute('id', 'password');
obj.parentNode.replaceChild(newO,obj);
newO.focus();
}
}
</script>
</head>
<body>
<div id="logindiv">
<img src="images/welcome.png" />
<div id="error" style="display:none; width:25%; height:40px; margin-left:39%; margin-right:auto; font-size:140%; background:#F33;
height:30px;
font-weight:bold;
color:#000;
display:none;
background-color:#F30;">
Incorrect login!
</div>
<form action="#">
<p><label for="name">Name</label> <input type="text" id="name" value="ACCOUNT NAME" onfocus="replaceName(this)" /></p>
<p><label for="password">E-mail</label> <input type="text" id="password" value="PASSWORD" onfocus="replacePass(this)" />
<p> <input type="image" src="images/login2.png" id="submit" onclick="Effect.BlindDown('error'); return false;" />
</form>
</div>
</body>
</html>
Difference is that I put the code straight to the onClick and it works?, I really need to put it into function. Check the site and see how it bugs