Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
Home
DiscussionsAccessExcelInfoPathOutlookPowerPointPublisherWord
DirectoryUser Groups
Related Topics
Outlook ExpressInternet ExplorerWindowsMS Server ProductsMore Topics ...

MS Office Forum / General MS InfoPath Questions / March 2006

Tip: Looking for answers? Try searching our database.

Basic Script for an addition

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
Marc - 16 Mar 2006 07:15 GMT
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
S.Y.M. Wong-A-Ton - 16 Mar 2006 12:00 GMT
The XPath to the nodes is not being recognized. Try adding "//" before the
nodes.
Instead of

itemNode.selectSingleNode("my:TotalAddition");

try

itemNode.selectSingleNode("//my:TotalAddition");

Do the same for the other nodes. To start learning about XPath go to:
http://www.w3.org/TR/xpath or http://www.w3schools.com/xpath/default.asp
---
S.Y.M. Wong-A-Ton

> 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
[quoted text clipped - 40 lines]
>
> Marc
Marc - 16 Mar 2006 20:21 GMT
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

> The XPath to the nodes is not being recognized. Try adding "//" before the
> nodes.
[quoted text clipped - 10 lines]
> ---
> S.Y.M. Wong-A-Ton
S.Y.M. Wong-A-Ton - 17 Mar 2006 17:38 GMT
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

> 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.
[quoted text clipped - 15 lines]
> > ---
> > S.Y.M. Wong-A-Ton
Marc - 17 Mar 2006 20:37 GMT
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

> Got it! You're calling
>
[quoted text clipped - 12 lines]
> ---
> S.Y.M. Wong-A-Ton
S.Y.M. Wong-A-Ton - 19 Mar 2006 19:28 GMT
To get to know more about programming with JScript, go to
http://msdn.microsoft.com/library/en-us/script56/html/0441e1e5-34e4-4d32-b188-f7
fc35613478.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.
---
S.Y.M. Wong-A-Ton

> Wong,
>
[quoted text clipped - 24 lines]
> > ---
> > S.Y.M. Wong-A-Ton
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.