View Full Version : on error show/hide div problem

11-03-2012, 04:20 PM

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.


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

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


Enter your username <input type = "text" id = "uname">
<span id = "message" style=color:"red"; style = "visibility:hidden">You must fill in your user name</span>
<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";



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