You need to sign in to do that
Don't have an account?
How to calculate sum of two number by using VF page And JavaScript
Can someone help me out to calculate the sum of VF page by using JS. I am trying with below code but not getting result when i enter numbers.
<apex:page >
<script>
function myFunction() {
var y = document.getElementById("{!$Component.num1}").value;
console.log(y);
var z = document.getElementById("{!$Component.num1}").value;
console.log(z);
var x = +y + +z;
console.log(x);
document.getElementById("{!$Component.demo}").innerHTML = x;
}
</script>
<apex:form id="form">
<apex:pageBlock >
<apex:inputText id="num1" label="Number1" onchange="myFunction()"/>
<apex:inputText id="num2" label="Number2" onchange="myFunction()"/>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection id="demo"></apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
<apex:page >
<script>
function myFunction() {
var y = document.getElementById("{!$Component.num1}").value;
console.log(y);
var z = document.getElementById("{!$Component.num1}").value;
console.log(z);
var x = +y + +z;
console.log(x);
document.getElementById("{!$Component.demo}").innerHTML = x;
}
</script>
<apex:form id="form">
<apex:pageBlock >
<apex:inputText id="num1" label="Number1" onchange="myFunction()"/>
<apex:inputText id="num2" label="Number2" onchange="myFunction()"/>
</apex:pageBlock>
<apex:pageBlock >
<apex:pageBlockSection id="demo"></apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
OUTPUT : -
I hope this will help you.
Kindly mark this as solved if the reply was helpful.
Thanks,
Kailash Chandra
All Answers
Sorry for this issue you are facing.
May I suggest you please give a try by using below code which works fine for me. Please let us know if this helps.
Kindly mark this as solved if the reply was helpful.
Thanks,
Nagendra
Please try the below code and let me know if this works for you. If still need modifications do let me know.
I hope you find the above solution helpful. If it does, please mark as Best Answer to help others too.
Thanks,
Ajay Dubedi
OUTPUT : -
I hope this will help you.
Kindly mark this as solved if the reply was helpful.
Thanks,
Kailash Chandra