LearnFast.Ninja

Input button disabled jQuery

Build button with text and id. Call to function that disabled the button. Add on click event for function call. The main idea is to use attr function with disabled. You can see how to do this in the working example code.

Step 1: Build button with text and id

<input type="button" value="My button" id="My_Btn"/>


Step 2: call to function that disabled the button

function Disable_Button(Elm_Id) {

    $("#" + Elm_Id).attr("disabled", "disabled");

}


Step 3: add on click event for function call

<input type="button" value="My button" id="My_Btn" onclick="Disable_Button('My_Btn')" />

The main idea is: 

$("#My_Btn").attr("disabled", "disabled");


Complete code:

<html>

<head>

    <title>input button disabled jQuery</title>

    <script type="text/javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>

    <script type="text/javascript">

        function Disable_Button(Elm_Id) {

            $("#" + Elm_Id).attr("disabled", "disabled");

        }

    </script>

</head>

<body>

    <input type="button" value="My button" id="Button1" onclick="Disable_Button('My_Btn')" />

</body>

</html>


Result:


Tags

jquery

input disabled