You need to sign in to do that
Don't have an account?
Anjaan
How to enable disabled button
Hello All,
I have used a checkbox with some button. The button is disabled by default. when the checkbox is checked it should be enabled. otherwise not. i am facing some problems you may help me. Its really urgent.
I am attaching the code
<apex:page >
<script type="text/javascript">
function enable(checkbox, btn){
if(checkbox.checked){
document.getElementById(btn).disabled = false;
}else{
document.getElementById(btn).disabled = true;
}
}
</script>
<apex:form id="myForm">
<h1>Congratulation</h1>This is your new Page
<apex:pageBlock >
<apex:inputCheckbox id="chk" onclick="enable(this,'{!$Component.pageblock.btn}');">
</apex:inputCheckbox>
<apex:pageblockButtons id="pageblock" location="bottom">
<apex:commandButton value="OK" id="btn" disabled = "true">
</apex:commandButton>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
I have used a checkbox with some button. The button is disabled by default. when the checkbox is checked it should be enabled. otherwise not. i am facing some problems you may help me. Its really urgent.
I am attaching the code
<apex:page >
<script type="text/javascript">
function enable(checkbox, btn){
if(checkbox.checked){
document.getElementById(btn).disabled = false;
}else{
document.getElementById(btn).disabled = true;
}
}
</script>
<apex:form id="myForm">
<h1>Congratulation</h1>This is your new Page
<apex:pageBlock >
<apex:inputCheckbox id="chk" onclick="enable(this,'{!$Component.pageblock.btn}');">
</apex:inputCheckbox>
<apex:pageblockButtons id="pageblock" location="bottom">
<apex:commandButton value="OK" id="btn" disabled = "true">
</apex:commandButton>
</apex:pageblockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Hope this helps.
Thanks and Regards
Osman Ashraf Bajwah
Software Engineer
Most Visualforce components have a rendered attribute, and you can rerender a section of a Visualforce page to force a partial page refresh. Chapter 12 of the Developer Guide has an example which, in part, does just that.
Hi there,
Rerender is not necessary. Try this:
Hi Sebastian,
I have also same problem, but I need to enable when deselected and disable when selected a check.
I was using below function
function checkBoxDisable(checkbox){
alert('checkbox1');
var checkBoxId=document.getElementById(checkbox.id);
alert('checkbox1=='+checkBoxId);
if(checkBoxId.checked==true){
alert('checkbox if 1);
disabled = true;
alert('checkbox if 2');
}
else{
alert('checkbox else 1');
disabled=false;
alert('checkbox else 2');
}
}