function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
Rick MacGuiganRick 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=""/>
Tavant TechnologiesTavant Technologies
Hi,
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