Disable buttons using JS

Use this board to ask questions or have discussions with other Rich Displays users.
Post Reply
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Disable buttons using JS

Post 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
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Disable buttons using JS

Post by dpankowski »

I have also tried get and getobj api's with the same results.
DaveLClarkI
Experienced User
Posts: 165
Joined: Wed Dec 11, 2013 10:40 am
First Name: Dave
Last Name: Clark
Company Name: WinWholesale, Inc.
Phone: 937-294-5331
Address 1: 31101 Kettering Blvd.
City: Dayton
State / Province: Outside Canada/USA
Zip / Postal Code: 45439
Country: United States
Contact:

Re: Disable buttons using JS

Post 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.
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Disable buttons using JS

Post 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.
dpankowski
Profound User
Posts: 35
Joined: Fri Jul 12, 2013 12:58 pm
First Name: Dan
Last Name: Pankowski
Company Name: Sinclair Services
Phone: 8015242956
Address 1: 550 E South Temple
City: Salt Lake City
State / Province: Utah
Zip / Postal Code: 84102
Country: United States
Contact:

Re: Disable buttons using JS

Post 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");
DaveLClarkI
Experienced User
Posts: 165
Joined: Wed Dec 11, 2013 10:40 am
First Name: Dave
Last Name: Clark
Company Name: WinWholesale, Inc.
Phone: 937-294-5331
Address 1: 31101 Kettering Blvd.
City: Dayton
State / Province: Outside Canada/USA
Zip / Postal Code: 45439
Country: United States
Contact:

Re: Disable buttons using JS

Post by DaveLClarkI »

dpankowski wrote:
if (checkbox.value = true)
{
That has bitten me a few times, too. Good catch.
Post Reply

Who is online

Users browsing this forum: No registered users and 1 guest