You need to sign in to do that
Don't have an account?
Help with Javascript!!
Hi Guys,
I have this code that should disable a two fields, the phone and the fax. However, only the phone is getting disabled when i click the checkbox. Could someone help me with this? thanks!
Regards,
Del
==============================
<script language="javascript">
function ToggleInput(theId)
{
var e = document.getElementById(theId);
if(e != null)
{
e.disabled = (e.disabled ? false : "disabled");
}
}
window.onload = function () { document.getElementById('{!$Component.phone}','{!$Component.fax}').enabled= "enabled"; }
</script>
<apex:inputCheckbox onchange="ToggleInput('{!$Component.phone}','{!$Component.fax}');" value="{!Lead.Copy__c}"/>
<apex:inputText id="phone" value="{!Lead.phone}"/>
<apex:inputText id="fax" value="{!Lead.fax}"/>
<apex:inputCheckbox onchange="ToggleInput('{!$Component.phone}','{!$Component.fax}');" value="{!Lead.Copy__c}"/>
In the above line you're calling a JS function ToggleInput and passing 2 parameters {!$Component.phone} and {!$Component.fax} but in the function you've defined only one parameter
please change the JS function as below
function ToggleInput(theId,faxid)
{
var e = document.getElementById(theId);
var fax = document.getElementById(faxid);
if(e != null)
{
e.disabled = (e.disabled ? false : "disabled");
fax.disabled = (fax.disabled ? false : "disabled");
}
}
All Answers
<apex:inputCheckbox onchange="ToggleInput('{!$Component.phone}','{!$Component.fax}');" value="{!Lead.Copy__c}"/>
In the above line you're calling a JS function ToggleInput and passing 2 parameters {!$Component.phone} and {!$Component.fax} but in the function you've defined only one parameter
please change the JS function as below
function ToggleInput(theId,faxid)
{
var e = document.getElementById(theId);
var fax = document.getElementById(faxid);
if(e != null)
{
e.disabled = (e.disabled ? false : "disabled");
fax.disabled = (fax.disabled ? false : "disabled");
}
}
Hi Gunners_23,
Great! This is working!thanks.
Can you help me with the formula to use. for example, aside from making the field disabled, i want to copy the value to another field. something like:
phone.value = fax.value;
thanks!
Del
Please refer the below code
function ToggleInput(theId,faxid)
{
var e = document.getElementById(theId);
var fax = document.getElementById(faxid);
if(e != null)
{
e.disabled = (e.disabled ? false : "disabled");
fax.disabled = (fax.disabled ? false : "disabled");
e.value = fax.value;
}
}
Once you get the id of the component then you can directly assign the value of one component to another