Page 1 of 1

Disable buttons using JS

Posted: Thu Feb 06, 2014 1:45 pm
by dpankowski
I want to disable or enabled a couple of buttons when the user clicks a check box using JavaScript.
The default is disabled, and when I click they will become enabled, but when I click it again it should turn the checkbox off and disabled the buttons.

Here's my onclick code for the checkbox:

var checkbox = document.getElementById("Checkbox1");

if (checkbox.value = true)
{
applyProperty("ChangeBTN", "disabled", "0");
applyProperty("DeleteBTN", "disabled", "0");
}
else
{
applyProperty("ChangeBTN", "disabled", "1");
applyProperty("DeleteBTN", "disabled", "1");
}

applyProperty("ChangeBTN", "field type", "graphic button"); // force field to be rerendard
applyProperty("DeleteBTN", "field type", "graphic button"); // force field to be rerendard

Re: Disable buttons using JS

Posted: Thu Feb 06, 2014 2:18 pm
by dpankowski
I have also tried get and getobj api's with the same results.

Re: Disable buttons using JS

Posted: Thu Feb 06, 2014 2:37 pm
by DaveLClarkI
Perhaps you want:

Code: Select all

changeElementValue("ChangeBTN", "disabled", false);
and:

Code: Select all

changeElementValue("ChangeBTN", "disabled", true);
Also, this may work in this situation:

Code: Select all

var checkbox = document.getElementById("Checkbox1");
but should really be as follows to work in all situations:

Code: Select all

var checkbox = getObj("Checkbox1");
Lastly, we were doing some things with disabled buttons here and found that the Profound buttons we were using don't look disabled to the end-user. So, we created a CSS class which we also added to the buttons, when disabled, in order to make them faded for the end-user's benefit.

Re: Disable buttons using JS

Posted: Thu Feb 06, 2014 4:43 pm
by dpankowski
Hi,

It dim's the buttons just fine, but it stays disabled/dimmed even after clicking the check box again.
and the checkbox stays checked.

Re: Disable buttons using JS

Posted: Thu Feb 06, 2014 7:24 pm
by dpankowski
Solved it, a co worker pointed out on the if statement I was using = not ==. Apparently you can assign values on an if statement. Here's the code:

var boxObj = getObj("Checkbox1");

if (boxObj.checked == true)
{
getObj("ChangeBTN").disabled = false;
getObj("DeleteBTN").disabled = false;
}
if (boxObj.checked == false)
{
getObj("ChangeBTN").disabled = true;
getObj("DeleteBTN").disabled = true;
}

// rerender the buttons

applyProperty("ChangeBTN", "field type", "graphic button");
applyProperty("DeleteBTN", "field type", "graphic button");

Re: Disable buttons using JS

Posted: Fri Feb 07, 2014 9:35 am
by DaveLClarkI
dpankowski wrote:
if (checkbox.value = true)
{
That has bitten me a few times, too. Good catch.