Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable and re-enable a button in with javascript?

I can easily disable a javascript button, and it works properly. My issue is that when I try to re-enable that button, it does not re-enable. Here's what I'm doing:

<script type="text/javascript">     function startCombine(startButton) {          startButton.disabled = 'true';          startButton.disabled = 'false';      } </script> <input type='button' id='start' value='Combine Selected Videos' onclick='startCombine(this);'> 

Why isn't this working, and what can I do to make it work?

like image 349
Adam Avatar asked Dec 06 '11 02:12

Adam


People also ask

How do I disable a button in JavaScript?

To disable a button using only JavaScript you need to set its disabled property to false . For example: element. disabled = true . And to enable a button we would do the opposite by setting the disabled JavaScript property to false .

How do you disable a button element?

You can disable the <button> element in HTML by adding the disabled attribute to the element. The disabled attribute is a boolean attribute that allows you to disable an element, making the element unusable from the browser.

How do you disable submit button in JavaScript after clicking it?

1.1 To disable a submit button, you just need to add a disabled attribute to the submit button. $("#btnSubmit"). attr("disabled", true); 1.2 To enable a disabled button, set the disabled attribute to false, or remove the disabled attribute.


1 Answers

true and false are not meant to be strings in this context.

You want the literal true and false Boolean values.

startButton.disabled = true;  startButton.disabled = false; 

The reason it sort of works (disables the element) is because a non empty string is truthy. So assigning 'false' to the disabled property has the same effect of setting it to true.

like image 62
alex Avatar answered Oct 06 '22 06:10

alex