We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Is there a way to disable the button after click on it.

Hi,

I need to disable a button after clicking on it and if a condition true then need to enable it again. Is there any way to do this?

Thank you,

Kalum


3 Replies

YA YuvanShankar Arunagiri Syncfusion Team October 31, 2022 12:07 PM UTC

Hi Kalum,


We have checked your reported query and prepared the sample based on your requirement. Please refer the below code snippet. Using the disabled property of button, we can change it dynamically based on condition.

@Html.EJS().Button("btn").Content("Primary").IsPrimary(true).Render()

<br />

@Html.EJS().CheckBox("checked").Change("onChange").Checked(false).Label("CheckBox").Render()

 

<script>

    document.getElementById("btn").addEventListener('click', function () {

        var Btn = document.getElementById("btn").ej2_instances[0];

        Btn.disabled = true;

    });

    function onChange(args) {

        if (args.checked) {

            var Btn = document.getElementById("btn").ej2_instances[0];

            Btn.disabled = false;

        }

    }

</script>


Could you please check the above code and get back to us, if you need any further assistance on this.


Regards, 

YuvanShankar A



KA kalum replied to YuvanShankar Arunagiri November 4, 2022 05:55 AM UTC

hi Yuvan,

It works fine. Thank you very much for your help.

Thanks

Kalum



NA Nivetha Anandan Syncfusion Team November 7, 2022 02:13 PM UTC

You’re welcome, Kalum.

If that post is helpful, please mark it as an answer so that other members can locate it more quickly.


Loader.
Live Chat Icon For mobile
Up arrow icon