views:

27

answers:

1

Hi Users,

I am using jquery to do enable/disable operation.

<script type="text/javascript">
        $(document).ready(function() {
            $("#ddlUser").change(function() {
                var selectedValue = $(this)[0].value;
                if (selectedValue == "--Select User--") {
                    $("#txtUserName").removeAttr("disabled");
                    $("#txtUserName").val("");
                    $("#txtPassword").removeAttr("disabled");
                    $("#txtPassword").val("");
                    $("#txtConfirmPassword").removeAttr("disabled");
                    $("#txtConfirmPassword").val("");
                    $("#txtEmailId").removeAttr("disabled");
                    $("#txtEmailId").val("");
                }
                else {
                    $("#txtUserName").attr("disabled", "disabled");
                    $("#txtPassword").attr("disabled", "disabled");
                    $("#txtConfirmPassword").attr("disabled", "disabled");
                    $("#txtEmailId").attr("disabled", "disabled");
                }
            });
        });
</script>



<%= Html.DropDownList("ddlUsers", (SelectList)ViewData["ddlUsers"], "--Select User--",   new { id = "ddlUsers", title = "Select User" })%>

Controller data passed as

 MembershipUserCollection lstUser = Membership.GetAllUsers();

  ViewData["ddlUsers"] = new SelectList(lstUser, "UserName", "UserName");  
A: 
 // Genereric watermarking function
jQuery.fn.waterMark = function (options) {
    var defaults = {
        activeColor: '#19254A',
        inActiveColor: '#19254A'
    };

    var settings = $.extend({}, defaults, options);

    return this.each(function () {
        var initVal = $(this).val();
        $(this).focus(function () {
            if ($(this).val() === initVal) {
                $(this).val('').css({ 'color': defaults.activeColor });
            }
            else { return false }
        });
        $(this).blur(function () {
            if ($(this).val() === '' || $(this).val() === initVal) {
                $(this).val(initVal).css({ 'color': defaults.inActiveColor });
            }
            else { return false }
        });
    });
}

and then you call it like [you must give an initial value to your text inputs like Type Search...]:

 $('input[type=text]').waterMark();

and for enable and disable:

$('input').attr('disabled', 'disabled');

and

$('input').attr('disabled', '');
XGreen