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
Disable buttons using JS
-
- 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:
-
- 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
I have also tried get and getobj api's with the same results.
-
- 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
Perhaps you want:
and:
Also, this may work in this situation:
but should really be as follows to work in all situations:
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.
Code: Select all
changeElementValue("ChangeBTN", "disabled", false);
Code: Select all
changeElementValue("ChangeBTN", "disabled", true);
Code: Select all
var checkbox = document.getElementById("Checkbox1");
Code: Select all
var checkbox = getObj("Checkbox1");
-
- 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
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.
It dim's the buttons just fine, but it stays disabled/dimmed even after clicking the check box again.
and the checkbox stays checked.
-
- 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
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");
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");
-
- 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
That has bitten me a few times, too. Good catch.dpankowski wrote:
if (checkbox.value = true)
{
Who is online
Users browsing this forum: No registered users and 9 guests