Operators in Salesforce
<apex:page >
<apex:form id="frm">
<apex:sectionHeader title="Operators" subtitle="calc"/>
<apex:pageBlock id="pb" title="calc">
<apex:pageBlockSection columns="6" id="pbs">
<apex:inputText id="first"/>
<apex:selectList id="ope" size="1" onchange="addi()">
<apex:selectOption itemLabel="+" itemValue="+"></apex:selectOption>
<apex:selectOption itemLabel="-" itemValue="-"></apex:selectOption>
<apex:selectOption itemLabel="*" itemValue="*"></apex:selectOption>
<apex:selectOption itemLabel="/" itemValue="/"></apex:selectOption>
</apex:selectList>
<apex:inputText id="second"/>
=<apex:inputText id="res" disabled="true"/>
<apex:commandButton value="Answer" onclick="cal()" reRender="none"/>
</apex:pageBlockSection>
</apex:pageBlock>
<script>
function addi()
{
var x = document.getElementById("{!$Component.frm.pb.pbs.first}").value;
var y = document.getElementById("{!$Component.frm.pb.pbs.second}").value
var z = document.getElementById("{!$Component.frm.pb.pbs.ope}").selectedIndex;
var a = document.getElementById("{!$Component.frm.pb.pbs.ope}").options[z].text;
var b = document.getElementById("{!$Component.frm.pb.pbs.res}");
//alert(a);
if(a == "+"){
var c = parseInt(x) + parseInt(y);
b.value = c;
}
else if(a == "-"){
var c = parseInt(x) - parseInt(y);
b.value = c;
}
else if(a == "*"){
var c = parseInt(x) * parseInt(y);
b.value = c;
}
else if(a == "/"){
var c = parseInt(x) / parseInt(y);
b.value = c;
}
}
function cal(){
var x = document.getElementById("{!$Component.frm.pb.pbs.first}").value;
var y = document.getElementById("{!$Component.frm.pb.pbs.second}").value;
var z = document.getElementById("{!$Component.frm.pb.pbs.ope}").selectedIndex;
var a = document.getElementById("{!$Component.frm.pb.pbs.ope}").options[z].text;
var b = document.getElementById("{!$Component.frm.pb.pbs.res}");
if(a == "+"){
var c = parseInt(x) + parseInt(y);
b.value = c;
}
else if(a == "-"){
var c = parseInt(x) - parseInt(y);
b.value = c;
}
else if(a == "*"){
var c = parseInt(x) * parseInt(y);
b.value = c;
}
else if(a == "/"){
var c = parseInt(x) / parseInt(y);
b.value = c;
}
}
</script>
</apex:form>
</apex:page>
Comments
Post a Comment