Wednesday, March 19, 2014

jQuery code to check if all textboxes are empty

$(document).ready(function() {
02    $('#btnSubmit').click(function(e) {
03        var isValid = true;
04        $('input[type="text"]').each(function() {
05            if ($.trim($(this).val()) == '') {
06                isValid = false;
07                $(this).css({
08                    "border": "1px solid red",
09                    "background": "#FFCECE"
10                });
11            }
12            else {
13                $(this).css({
14                    "border": "",
15                    "background": ""
16                });
17            }
18        });
19        if (isValid == false)
20            e.preventDefault();
21        else
22            alert('Thank you for submitting');
23    });
24});​

No comments:

Post a Comment