You need to sign in to do that
Don't have an account?
Enable button when check box is selected
Hi I am using a java script method from visual force to make sure only one check box is selected in pageblocktable at a time.
Here is the script;
<script>
var selectedChkbox;
function deSelectOthers(chkBox) {
if (chkBox.checked) {
if ((chkBox != selectedChkbox) && (selectedChkbox != null)) {
selectedChkbox.checked = false;
}
selectedChkbox = chkBox;
}
}
</script>
part of page code that calls this function is;
<apex:inputCheckBox value="{!obj.isChecked}"
onclick="deSelectOthers(this)">.. This works perfectly fine...
Now I have a button which by default is disabled. I need to enable this button only when a check box is selected..can somebody tel me how we can accomplish this..Thanks in advance.
Hi,
If you want to enable a button, you can write a javascript to achieve this.
Using following syntax you can get the reference of a button.
{!$Component.theButtonId}
then pass this Id to Javascript and set its "enable" property as true.
Hope this helps you!!
Hi,
Pls refer the following javascript code :
function enableButton()
{
// if your are using visualforce command button, and make sure you following complete hiererchy of components in //page to access command button id as bold text
document.getElementById("{!$Component.buttonId}").className="btn";
document.getElementById("{!$Component.buttonId}").disabled=false;
// if you are using simple html button then try below commented line
// document.getElementById("buttonId").disabled=true;
}
Hi, highlighted in bold are the changes i made based on your inputs..pls advise whats wrong.
function deSelectOthers(chkBox,'{!$Component.btn}') {
var buttons = '{!$Component.btn}';
if (chkBox.checked) {
if ((chkBox != selectedChkbox) && (selectedChkbox != null)) {
selectedChkbox.checked = false;
document.getElementById('buttons').enable = false;
}
selectedChkbox = chkBox;
document.getElementById('buttons').enable = true;
}
}
</script>
// calling js function
<apex:inputCheckBox value="{!obj.isChecked}"
onclick="deSelectOthers(this, '{!$Component.btn}')">
// button id
<apex:commandButton value="Continue" id="btn" disable = "true"/>
Thanks
Hi,
Try the code given below -
function deSelectOthers(chkBox)
{
if (chkBox.checked)
{
if ((chkBox != selectedChkbox) && (selectedChkbox != null))
{
selectedChkbox.checked = false;
}
selectedChkbox = chkBox;
document.getElementById("{!$Component.btn}").className="btn";
document.getElementById('{!$Component.btn}').disabled = false;
}
}
</script>
// calling js function
<apex:inputCheckBox value="{!obj.isChecked}"
onclick="deSelectOthers(this)">
// button id
<apex:commandButton value="Continue" id="btn" disable = "true"/>
Hi Alok,
Tried your soultion.but didnt work.
Thanks.
//Script
function dispalydivfun(chkBox){
if (chkBox)
{
document.getElementById("{!$Component.buttoncon}").className="btn";
}
else{
document.getElementById("{!$Component.buttoncon}").className="btnDisabled";
}
}
//Check box
<apex:inputCheckbox value="{!chkBox}" onchange="dispalydivfun(this.checked)" />
//Button
<apex:commandButton value=" Continue " id="buttoncon" disabled="true"/>