By default, Kentico already assigns a CSS class to the control's parent in error. See the sample markup:
<li>
<label class="EditingFormLabel" for="txtText">First name:</label>
<div class="EditingFormControlNestedControl editing-form-control-nested-control Error">
<input name="txtText" type="text" maxlength="200" class="form-control">
</div>
<span class="EditingFormErrorLabel">Please enter a value.</span>
</li>
So there should be no need to create a javascript function to do this. Simply add this style:div.Error input { background-color: red; }