I have the following basic xpage. I wan to add the fields on the reg1 and over1 and show it on total1. I think I have to update the over1 field to refelect the new value or something like that. It always shows 0. Any ideas?
<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core"
xmlns:xe="http://www.ibm.com/xsp/coreex">
<xp:this.data>
<xp:dominoDocument var="document1" formName="TestHrs"></xp:dominoDocument>
</xp:this.data>
<xp:table style="width:383.0px">
<xp:tr>
<xp:td>Regular</xp:td>
<xp:td>Overtime</xp:td>
<xp:td>Total</xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xe:djNumberTextBox id="reg1"
value="#{document1.rgHr1}">
</xe:djNumberTextBox>
</xp:td>
<xp:td>
<xe:djNumberTextBox id="over1"
value="#{document1.ovHr1}">
<xe:this.onChange><![CDATA[var reg1 = getComponent("reg1").getValue()
var over1 = getComponent("over1").getValue();
getComponent("total1").setValue(reg1 + over1);]]></xe:this.onChange>
</xe:djNumberTextBox>
</xp:td>
<xp:td>
<xe:djNumberTextBox id="total1"
value="#{document1.toHr1}" readOnly="true">
</xe:djNumberTextBox></xp:td>
</xp:tr>
<xp:tr>
<xp:td>
<xe:djNumberTextBox id="reg2"
value="#{document1.rgHr2}">
</xe:djNumberTextBox>
</xp:td>
<xp:td>
<xe:djNumberTextBox id="over2"
value="#{document1.ovHr2}">
<xe:this.onChange><![CDATA[#{javascript:var total1 = getComponent("reg2").getValue() + getComponent("over2").getValue();
getComponent("total2").setValue(total2);}]]></xe:this.onChange>
</xe:djNumberTextBox>
</xp:td>
<xp:td>
<xe:djNumberTextBox id="total2"
value="#{document1.toHr2}" readOnly="true">
</xe:djNumberTextBox></xp:td>
</xp:tr>
</xp:table>
</xp:view>
I would recommend not to use ssjs but csjs for this. In the same event but with client Javascript, sum the values and put the total in the total field.
Keep in mind that as a readonly field, maybe you should check the property "Show disabled control for read-only".
Maybe you will need to do the sum in the querySave event of the document because as a read-only field the value is not updated. Not sure about this.