simple validation without jquery
by Terrance Smith
HTML
<div>
<label>Please Input Your Name
<input type="text" id="testVal" />
</label>
<input type="button" id="valBtn" value="Validate" onclick="validateTextField();" />
</div>
<br />
<br />
<br />
<a href="http://stackoverflow.com/questions/799981/document-ready-equivalent-without-jquery">How to do document.ready without jquery</a>
CSS
label {
color: #B4886B;
font-weight: bold;
display: block;
width: 150px;
float: left;
}
JavaScript
//without jquery
window.validate = function (testVal) {
var result = false;
result = (!testVal) ? false : true;
return result;
};
function validateTextField() {
var textVal = document.getElementById("testVal").value,
isValid = validate(textVal),
message = (isValid) ? "Heeeey " + textVal : "Please Input a name";
alert(message);
}