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
PRIYAN NEERUDUPRIYAN NEERUDU 

priyan

m trying to add two input textvalues using javascript ...but using below code m unable to do....how i can get dis functioanlity done

-------------------------------------------------------------------------
<apex:page >
<apex:form >
 <p id="demo"></p>
<apex:inputText id="txt1"/>
<apex:inputText id="txt2"/>


<script>
      function myFunction() {
        var y = document.getElementById("txt1").value;
        var z = document.getElementById("txt2").value;
        var x = y + z;
        document.getElementById("c").innerHTML = x;
      }
    </script>

<p id="demo"></p>

<apex:pageBlock >
<apex:pageBlockButtons location="bottom">
<apex:commandButton onclick="sum()" value="sum"/>
</apex:pageBlockButtons>
</apex:pageBlock>
</apex:form>
</apex:page>
Best Answer chosen by PRIYAN NEERUDU
GauravGargGauravGarg
Hi Priyan,

Please try below code, this is working as expected in my org.
<apex:page id="pg">
<apex:form id="frm">
 <apex:pageBlock id="pb">
     <apex:pageblockSection id="pbs">
    <apex:inputText id="txt1" label="Input 1"/> <br/>
    <apex:inputText id="txt2" label="Input 2"/><br/>
    <apex:outputText id="c" label="Output"/>
    <script>
      function myFunction() {
        var y = document.getElementById("pg:frm:pb:pbs:txt1").value;
        var z = document.getElementById("pg:frm:pb:pbs:txt2").value;
        var x = parseInt(y) + parseInt(z);
        document.getElementById("pg:frm:pb:pbs:c").innerHTML = x;
      }
    </script>
    <apex:commandButton onclick="myFunction();return false;" value="sum" />
    </apex:pageblockSection>
</apex:pageBlock>
</apex:form>
</apex:page>

If this works for you, please mark it best answer or let me know if you face issues in it.

Thanks,

Gaurav
Email: gauravgarg.nmims@gmail.com