Adding Numeric Values in Drop-Down List - InfoPath Dev
in

InfoPath Dev

Adding Numeric Values in Drop-Down List

Last post 01-04-2006 12:35 AM by Nagesh. 3 replies.
Page 1 of 1 (4 items)
Sort Posts: Previous Next
  • 01-01-2006 01:33 PM

    Adding Numeric Values in Drop-Down List

    I have a list of numeric values in a drop-down list. I need to sum all the values up for the totals. How can I sum it up with javascript? Please help.



  • 01-02-2006 06:41 AM In reply to

    Re: Adding Numeric Values in Drop-Down List

    Hi,
    Is your dropdown binded to a Dataconnection or did you enter values entries manually?

    If dropdown is binded to a dataconnection then here are the steps,

    //Get dataconnection DOM which populates the dropdown.
    var domDataConnection = XDocument.GetDom("dataconnectionname");
    //Get list of repeating nodes which fill the dropdown
    var nodeList = XDocument.DOM.selectNodes("/my:myFields/my:group1/my:field1");
    var sum = 0;

    //Iterate through the node list and calculate the sum
    for(var i = 0; i< nodeList.length; i++)
    {
    var svalue = nodeList.text;
    sum = sum + parseInt(svalue);
    }
    return sum;

    Hope this helps!

    K.Ramana Reddy
    K.Ramana Reddy / http://www.ggktech.com
    India.
  • 01-02-2006 10:14 PM In reply to

    Re: Adding Numeric Values in Drop-Down List

    Thanks for trying to help out Ramanda. The values are coming from a Sharpoint dataconnection that called all the forms submitted to a Sharepoint Library. For example, I have 3 forms submitted and saved to a Sharepoint library. Form1 will have a value 3 in field1, form2 will have value 5 in field1, and form3 will have the value of 7 in field1. Now, Onload(), field2 Drop-down list will contain the values 3,5,7. I need field3 to have the total of 15! How would I be able to do that? Thanks in advance.


    Regards,

    A.J.

  • 01-04-2006 12:35 AM In reply to

    • Nagesh
    • Not Ranked
    • Joined on 07-21-2005
    • India
    • Posts 5

    Re: Adding Numeric Values in Drop-Down List

    Hi adouangpanya,

    Please follow these steps to get that,

    1) You first make “field1” as promoted property for the first form and then publish to sharepoint library
    (let it be named as “DemoLib”).
    2) Now create from1,form2,form3 from DemoLib as you said
    3) Take data connection to that library in your new InfoPath form(let the connection be named as “DemoLibConn”) and during this process check the box with name “field1”
    4) Add a drop down list(name it field1) to the form and populate it with the values of “field1” from DemoLibConn using DropDownListProperties.
    5) Add a TextBox (name it field2) which holds the sum.
    6) In the Onload() you use the following code

    var domDataConnection = XDocument.GetDOM("DemoLibConn ");
    //Get list of repeating nodes which fill the dropdown
    domDataConnection.setProperty("SelectionNamespaces", "xmlns:dfs=\"http://schemas.microsoft.com/office/infopath/2003/dataFormSolution\"");
    var nodeList = domDataConnection.selectNodes("/dfs:myFields/dfs:dataFields/dfs:DemoLib/@field1");
    var sum = 0;
    //Iterate through the node list and calculate the sum
    for(var i = 0; i< nodeList.length; i++)
    {
    var svalue = nodeList.text;
    sum = sum + parseInt(svalue);
    }
    XDocument.DOM.selectSingleNode("/my:myFields/my:field2").text = sum;

    7) Preview the form and you should observe the sum populated in field2

    If you are using your own names then change the code at respective points and also include the namespace of your form in setProperty() as it may be different for your form.

    Thanks


    Nagesh
    InfoPath Dev India
Page 1 of 1 (4 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.