+ Start a Discussion
SHAIK MOHAMMAD YASEENSHAIK MOHAMMAD YASEEN 

i am new to salesforce can anyone help me with a code for adding two numbers on a vf page using jaascript???

Please help me with code for adding two numbers on visualforce page using javascript on the page
Best Answer chosen by SHAIK MOHAMMAD YASEEN
Prateek Singh SengarPrateek Singh Sengar
Hi,
A Very basic version of the VF page would be 
 
<apex:page >
    <script>
    function add_number() {
			var first_number = parseInt(document.getElementById('{!$Component.myFrm.Text1}').value);
        	var second_number = parseInt(document.getElementById('{!$Component.myFrm.Text2}').value);
       		var result = first_number + second_number;

            document.getElementById('{!$Component.myFrm.txtresult}').value = result;
        }
    </script>
    
    <apex:form id="myFrm">
    	<apex:inputText id="Text1"/>
        <apex:inputText id="Text2"/>
        <apex:commandButton onclick="return add_number()" value="Add Number" reRender="x"/>
        <apex:inputText id="txtresult"/>
    </apex:form>
    
</apex:page>

Please mark the thread as solved if the solution helps.