Skip to content

Instantly share code, notes, and snippets.

@liliycode
Created November 18, 2017 20:58
Show Gist options
  • Save liliycode/34935442e7f50e1e87c90bfe4c850b21 to your computer and use it in GitHub Desktop.
Save liliycode/34935442e7f50e1e87c90bfe4c850b21 to your computer and use it in GitHub Desktop.
<!DOCTYPE html>
<head>
<script>
function validate() {
var inputObject = document.getElementById("name");
var paraObject = document.getElementById("response");
if ((inputObject.value.trim() == "") || (inputObject.value == null)) {
alert("Invalid input!");
}
else {
paraObject.innerHTML = inputObject.value;
}
function blue(inputObject) {
inputobject.style.border = "2px solid blue";
}
function required(inputObject) {
if (inputObject.value.trim() == "") {
inputObject.style.border = "2px solid red";
}
else {
inputObject.style.border = "2px solid green";
} }
</script>
</head>
<body>
Name:
<br/>
<input id="name" type="text" name="nameinput" onBlur="required(this)" onFocus="blue(this)"/>
<button class="button" onClick="validate()">Validate Name Input</button>
<br/>
<p id="response">TEST</p>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment