Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I want to disable link button after clicking of it and other enable. toggle enable/ disable between both link buttons using javascript

Tags:

javascript

I want to disable link button after clicking of it & other enable. toggle enable/ disable between both link buttons using javascript

<a id="a1" href="page1.aspx">One</a><a id="a2" href="page2.aspx">Two</a>
like image 271
Yogini Avatar asked Feb 19 '09 11:02

Yogini


People also ask

How do I disable one button when I click the other button?

attr("disabled", true); } $("#form2"). toggle(); }); This will disable the opposite button upon clicking, and re-enable it upon clicking again.

How do I disable toggle button?

To disable a toggle switch, add the disabled attribute to the toggle's checkbox input. When disabled, the toggle appears gray. The user cannot change the state of the toggle. And the present state is reflected in both the location of the toggle switch and by the “on” state being a slightly darker gray.

How do you disable a link in Java?

To disable links: $("td > a"). attr("disabled", "disabled"). on("click", function() { return false; });


2 Answers

Simple, just add listeners to the onclick events on both links, that disable the link in question and enable the other one.

Something like

document.getElementById('a1').onclick = function() {
   document.getElementById('a1').disabled = true;
   document.getElementById('a2').disabled = false;
};

document.getElementById('a2').onclick = function() {
   document.getElementById('a2').disabled = true;
   document.getElementById('a1').disabled = false;
};

Of course if you're going to be extending this to multiple buttons then you could easily abstract the above out to registration methods, looping over arrays of buttons etc. (possibly those that implement a particular class rather than explicitly specifying the array).

like image 75
Andrzej Doyle Avatar answered Sep 28 '22 19:09

Andrzej Doyle


The simplest way is to hide the link rather than to make it disabled.

You can use this code to hide the link after click on it.

Its tested code & it worked perfect for me. :-)

<script type="text/javascript">
    onclick = function() {
        var chk= document.getElementById('myElementId');
        chk.style.display="none"; 
    };
</script>
like image 37
PHP Ferrari Avatar answered Sep 28 '22 18:09

PHP Ferrari