I was looking through the articles and couldn't find anything to help me. When the user clicks submit and the name is empth I want to display a messege next to it saying username is empty. I van get the message to display but it refreshes and goes away again. I am learning javascript by myself so I am sorry if it is a easy fix. Below is my code. Thanks in advance.
<!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>Contact Us</title>
<link type="text/css" rel="stylesheet" href="style.css" />
<link type="text/css" rel="stylesheet" href="contact.css" />
<script type="text/javascript">
function validate(){
var name = document.getElementById('name').value;
var email = document.getElementById('email').value;
var emailC = document.getElementById('emailC').value;
var cmt = document.getElementById('cmt').value;
var nme = document.getElementById('nme');
if(name == ""){
nme.innerHTML="Please enter your name";
nme.style.color="red";
return false;
}
else{
nme.innerHTML="Name OK";
nme.style.color="green";
return true;
}
}
</script>
</head>
<body>
<div id="container">
<div id="header">
<div id="headText">
Ned Kelly's
</div><!--end of headText-->
<div id="headText2">
Bar Tipperary
</div><!--end of headText-->
</div><!--end of header-->
<div id="navbar">
<div id="tabs">
<ul>
<li><a href="index.php">Home</a></li>
<li><a href="events.html">Events</a></li>
<li><a href="#">Photos</a></li>
<li><a href="#">Contact</a></li>
</ul>
</div>
</div><!--end of navbar-->
<div id="content">
<div id="cont">
<form action="#" method="post" name="form" id="myForm">
<h3>Our Form</h3>
<hr/>
<ul>
<li>Name:
<input type="text" name="name" id="name"/>
<label id="nme"></label>
</li>
<li>Email:
<input type="text" name="name" id="email"/>
</li>
<li>Confirm Email:
<input type="text" name="name" id="emailC"/>
</li>
<li>Comment:
<textarea rows="3" cols="16" maxlength="100" id="cmt"></textarea>
<br/>
<br/>
<br/>
<br/>
</li>
</li>
<input type="submit" value="Submit" id="submit" onclick="validate()"/>
</ul>
</form>
</div>
</div><!--end of content-->
</div><!--end of container-->
<div id="footer">
<hr/>
Designed by <a href="#">Edmond P Murphy</a> 2013
</div>
</body>
</html>