1) When you want to manipulate the "value" of an <input>
element , you do not use innerHTML. You manipulate it by accessing its value attribute like this :
document.getElementById("MY_INPUT_ID").value = 'Cannot Be Blank';
2) When you want to make validation on multiple fileds then you do it on the form submission and not in "real time". If you want to make "real time" validation then it is better to focus only on one field each time.(If other restrictions do not apply).
3) onChange event is for <select>
elements and does not fire upon <input>
elements. If you want to "monitor" an <input>
element you should use
4) You should not insert "Cannot Be Blank" in the input field , cause it will count as text and you will have issues. If you want to display a message then you need to create a container with your message next to your input.
The following code is more of an example to get you to the right direction of what you are trying to do.
<input type='text' name='aInput' id='aInput' onkeyup='validate(this);'></input>
<input type='text' name='bInput' id='bInput' onkeyup='validate(this);'></input>
<div id='error'></div>
<script language="JavaScript">
function validate(el){
var myInputValue = el.value;
var myInputID = el.id;
if(myInputValue === ''){
document.getElementById(myInputID).style.backgroundColor = 'rgba(255,0,0,0.32)';
document.getElementById('error').innerHTML = el.name + " Cannot Be Blank";
}else{
document.getElementById(myInputID).style.backgroundColor = '#fff';
document.getElementById('error').innerHTML = "";
}
}
</script>