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

3

48

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?

Eliciaelicit answered 6/12, 2011 at 2:15 Comment(0)
P
86

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.

Pettway answered 6/12, 2011 at 2:16 Comment(1)
How to enable button that was disabled in HTML <Button disabled/>Filippo
T
6
<script>
function checkusers()
{
   var shouldEnable = document.getElementById('checkbox').value == 0;
   document.getElementById('add_button').disabled = shouldEnable;
}
</script>
Tittle answered 21/8, 2013 at 6:0 Comment(0)
R
1

you can try with

document.getElementById('btn').disabled = !this.checked"

<input type="submit" name="btn"  id="btn" value="submit" disabled/>

<input type="checkbox"  onchange="document.getElementById('btn').disabled = !this.checked"/>
Respirable answered 31/1, 2017 at 16:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.