-1

Hello guys how to change a color of a textbox in cshtml?. I have this code

$("#BUTTON").click(function (event) {
    var urlPA = URL;
    var crty = $("#Courtesy").val();
    var fname = $("#Familyname").val();
    var gname = $("#GivenName").val();

    if (crty != 0 && fname != 0 && gname != 0) {
        $.ajax({
            type: "GET",
            url: urlPA,

            data: 'DATA',
            success: function (response) {
                alert(response);
            /// when success the color of the textbox return to normal
            },
            datatype: "text"
        });
    } else { alert("Please fill up the required fields.");
     ////// when error the textbox background makes red

}
});

How to do it?. Thanks.

Gilad Green
  • 36,708
  • 7
  • 61
  • 95
UkI
  • 1
  • 10
  • @GiladGreen Its different. I have a condition when if the textbox will change the color or not. See code example. – UkI Jul 11 '16 at 08:30

1 Answers1

0

You can use jQuery's css function to set an inline style:

if (crty != 0 && fname != 0 && gname != 0) {
    $.ajax({
        type: "GET",
        url: urlPA,

        data: 'DATA',
        success: function (response) {
            alert(response);
            /// when success the color of the textbox return to normal
            $('#Courtesy').css('background-color', 'white');
            // add other fields
        },
        datatype: "text"
    });
} else { alert("Please fill up the required fields.");
    ////// when error the textbox background makes red
    $('#Courtesy').css('background-color', 'red');
    // add other fields
}