0

I Have Validate my form with javascript. I want to set ErrorControl css code. But I can't able to get the output.

<style type="text/css">
    .ErrorControl
    {
        background-color: #FBE3E4;
        border: solid 1px Red;
    }
</style>

<script type="text/javascript">
    $(document).ready(function () {
        //HighlightControlToValidate();
        $("#Button1").click(function () {
            if (typeof (Page_Validators) != "undefined") {
                for (var i = 0; i < Page_Validators.length; i++) {
                    if (!Page_Validators[i].isvalid) {
                        $('#' + Page_Validators[i].controltovalidate).className = "ErrorControl";
                    }
                    else {
                        $('#' + Page_Validators[i].controltovalidate).css("border", "solid 1px White");
                    }
                }
            }
        });
    });
 </script>
1
  • What is shown in console ? Commented Feb 27, 2014 at 8:58

2 Answers 2

1

Try this

<script type="text/javascript">
$(document).ready(function () {
    //HighlightControlToValidate();
    $("#Button1").click(function () {
        if (typeof (Page_Validators) != "undefined") {
            for (var i = 0; i < Page_Validators.length; i++) {
                if (!Page_Validators[i].isvalid) {
                    $('#' + Page_Validators[i].controltovalidate).addClass( "ErrorControl");
                }
                else {
                    $('#' + Page_Validators[i].controltovalidate).css("border", "solid 1px White");
                }
            }
        }
    });
});

Sign up to request clarification or add additional context in comments.

Comments

1

Try changing

$('#' + Page_Validators[i].controltovalidate).className = "ErrorControl";

to

$('#' + Page_Validators[i].controltovalidate).addClass("ErrorControl");

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.