You need to sign in to do that
Don't have an account?
Rick MacGuigan
onChange event and jscript function not working
I'm trying to calculate a value on a visual force page based on an onChange event on a field but the input type id='answer' is not showing on the page.
Any ideas on what I'm missing ?
<script>
function checkNumbers(ele, classname) {
var value = document.getElementsByClassName(classname);
var val1 = parseInt(document.getElementById("value1").value);
var val2 = parseInt(document.getElementById("value2").value);
var tot = val1 + val2;
var ansD = document.getElementById("answer");
ansD.value = val1 + val2;
document.getElementById(“answer”).innerHTML=tot;
if (tot < 100) {
value.ansD.value = " Percent Radius of operations not equal to 100."
} else {
value.ansD.value = " Percent Radius of operations equal to 100."
}
}
</script>
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Long_Haul__c}" style="color:blue;" id="value1" onchange="checkNumbers(this, 'sel1')" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Long-Haul') && (RadiusOfOperations)}" >
<apex:actionSupport event="onchange" reRender="longhaul" />
</apex:inputField>
<!-- <apex:outputPanel id="longhaul"> -->
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Long_HaulX__c}" id="longhaul" style="color:green;" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Long-Haul') && (RadiusOfOperations)}" />
<!-- </apex:outputPanel> -->
Answer = <input type="text" id="answer" name="answer" value=""/>
Any ideas on what I'm missing ?
<script>
function checkNumbers(ele, classname) {
var value = document.getElementsByClassName(classname);
var val1 = parseInt(document.getElementById("value1").value);
var val2 = parseInt(document.getElementById("value2").value);
var tot = val1 + val2;
var ansD = document.getElementById("answer");
ansD.value = val1 + val2;
document.getElementById(“answer”).innerHTML=tot;
if (tot < 100) {
value.ansD.value = " Percent Radius of operations not equal to 100."
} else {
value.ansD.value = " Percent Radius of operations equal to 100."
}
}
</script>
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Long_Haul__c}" style="color:blue;" id="value1" onchange="checkNumbers(this, 'sel1')" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Long-Haul') && (RadiusOfOperations)}" >
<apex:actionSupport event="onchange" reRender="longhaul" />
</apex:inputField>
<!-- <apex:outputPanel id="longhaul"> -->
<apex:inputField value="{!Comm_Auto_Audit_Sample_Policy__c.Percent_Long_HaulX__c}" id="longhaul" style="color:green;" rendered="{!CONTAINS(Comm_Auto_Audit_Sample_Policy__c.Radius_of_Operations__c,'Long-Haul') && (RadiusOfOperations)}" />
<!-- </apex:outputPanel> -->
Answer = <input type="text" id="answer" name="answer" value=""/>
Try this one
var val1 = document.getElementById('pageId:formId:value1').value);
<apex:page id="pageId">
<apex:form id="formid">
<apex:inputfield id="value1 />
</apex:form>
</apex:page>
Thanks