Basic Script for an addition

M

Marc

I’m trying to do something as easy as to add the content of two boxes called
Total (which is the result of another addition) and Transport (which the user
enters manually) in a third one called TotalAddition. I don’t want to use an
expression box because my aim is to start understanding basic Script.

The Script I’ve entered is:

/*------------------------------------------------------------------------------ CalcAddTotalAmount Adds perdiems and transport

------------------------------------------------------------------------------*/

function AddTotalAmount(itemNode)
{
var nTotalAddition = itemNode.selectSingleNode("my:TotalAddition");
var nPerdiems = itemNode.selectSingleNode("my:Total");
var nTransport = temNode.selectSingleNode("my:Transport").nodeTypedValue;

if (isNaN(nPerdiems))
nPerdiems = 0;

if (isNaN(nTrasnport))
nTransport = 0;

nTotalAddition.nodeTypedValue = (nPerDiems + nTransport);

}

THEN THE FOLLOWING HANDLER

function msoxd_my_Transport::OnAfterChange(eventObj)
{

if (eventObj.IsUndoRedo) return;

AddTotalAmount();

}

The message I get when I enter data in Transport is ‘Item Node is null or
not an object’. Could anyone correct my basic Script?

Thank you,

Marc
 
M

Marc

Thank you Wong but it still gives me the same error. It should be something
so easy, but I cannot work out where the error is.

Marc
 
S

S.Y.M. Wong-A-Ton

Got it! You're calling

AddTotalAmount();

in

function msoxd_my_Transport::OnAfterChange(eventObj)
{
...
}

without passing a parameter, while the function "AddTotalAmount" expects a
parameter "itemNode". So logically, when the code in "AddTotalAmount" runs,
"itemNode" will be null. You need to pass a parameter to the function.
---
S.Y.M. Wong-A-Ton


Marc said:
Thank you Wong but it still gives me the same error. It should be something
so easy, but I cannot work out where the error is.

Marc
 
M

Marc

Wong,

Sorry for my ignorance but I don't know how to pass a parameter to the
function. My objective is to get a basic understanding of how this works and
then contract someone to prepare the forms we need, but I need at least to be
able to do something as easy as this if I want to understand what can be done
with InfoPath and XML.

Thank you for your time.

Marc
 
S

S.Y.M. Wong-A-Ton

To get to know more about programming with JScript, go to
http://msdn.microsoft.com/library/e...e5-34e4-4d32-b188-f7fc35613478.asp?frame=true

When you call AddTotalAmount() you need to pass a parameter, in this case it
is expecting an XML node like this:

AddTotalAmount(myNode);

where "myNode" is the parameter. I'm not familiar with your scenario, so
you'll have to figure out what the XML node is that the function expects.

If you want to explore the full capabilities of InfoPath, you'll need to
have previous programming experience with JScript, VBScript, or a .NET
language, as well as know XML, XSLT, and XPath, and a little about databases
and web services.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top