The problem I'm having is, if the user leaves the userdata
input blank, I want it to target that input and display text, notifying them that it's a required field.
I'm using innerHTML
to send the message to a div
or directly to the input field but nothing is displayed. I have also tried to use <p>
, <span>
and that did not work either. Any help is appreciated.
<!doctype html>
<html>
<head>
</head>
<body>
<form>
<input type="text" id="user1">
<div id="error"></div>
<button onClick="test()">Work</button>
</form>
<script type="text/javascript">
function test(){
var userdata = document.getElementById("user1").value;
if(userdata == ""){
document.getElementById("error").innerHTML="Please fill in Blanks";
}
}
</script>
</body>
</html>