Created
November 18, 2017 20:58
-
-
Save liliycode/34935442e7f50e1e87c90bfe4c850b21 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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