asp.net - Change associated textbox color with jquery on client validation -
i want use jquery select associated element's parent required , change css class.
i need add css class "error" parent div of span required field. (this color textbox according css).
i have following html markup gets generated aspx page:
<div class="control-group"> <label>your name</label> <input name="ctl00$maincontent$txtname" type="text" maxlength="100" id="maincontent_txtname"> <span data-val-controltovalidate="maincontent_txtname" data-val-errormessage="your name required" data-val-display="dynamic" id="maincontent_txtnamerequired" class="error" data-val="true" data-val-evaluationfunction="requiredfieldvalidatorevaluateisvalid" data-val-initialvalue="" style="display:none;">this field required</span> </div>
after "client validation" span gets changed to:
<span data-val-controltovalidate="maincontent_txtname" data-val-errormessage="your name required" data-val-display="dynamic" id="maincontent_txtnamerequired" class="error" data-val="true" data-val-evaluationfunction="requiredfieldvalidatorevaluateisvalid" data-val-initialvalue="" style="display: inline;">this field required</span>
and after server postback span actually:
<span data-val-controltovalidate="maincontent_txtname" data-val-errormessage="your name required" data-val-display="dynamic" data-val-isvalid="false" id="maincontent_txtnamerequired" class="error" data-val="true" data-val-evaluationfunction="requiredfieldvalidatorevaluateisvalid" data-val-initialvalue="">this field required</span>
i use 1 javascript function not require onclick function on each button used. want reuse same function on many pages.
while couldn't find answer based on how based on span , data elements, instead hour or later found question helped me come solution:
<script type="text/javascript"> $(document).ready(function () { $("form").submit(function () { if (typeof page_validators != 'undefined') { var errors = ''; $.each(page_validators, function () { if (!this.isvalid) { $(this).parent().addclass("error"); } }); } }); }); </script>
Comments
Post a Comment