...

View Full Version : on error show/hide div problem



katmac
11-03-2012, 05:20 PM
Hi,

I have a login screen if the user doesn't enter a username, I want a box just underneath the page title to display an error message for a few seconds and then return focus to the username field. This is how my boss wants it.

I am having a difficult time trying to do this.

I have attached my code. If someone could help me out that would be great.

Thanks.

optimizer123
11-03-2012, 10:31 PM
Please copy/paste your codes here. thanks.

Philip M
11-03-2012, 11:56 PM
Try this example:-


<html>
<head>
<body>

Enter your username <input type = "text" id = "uname">
<br>
<span id = "message" style=color:"red"; style = "visibility:hidden">You must fill in your user name</span>
<br>
<input type = "button" value = "Submit" onclick = "checkun()">

<script type = "text/javascript">
function checkun() {
var u = document.getElementById("uname").value;
if (u.length < 3) {
document.getElementById("message").style.visibility = "visible";
setTimeout(clearit,4000); // show for 4 seconds
}
}

function clearit() {
document.getElementById("message").style.visibility = "hidden";
document.getElementById("uname").focus();
}

</script>

</body>
</html>


Quizmaster: Which southern European country was ruled by Antonio Salazar from 1932 to 1968?
Contestant: Russia.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum