Jscript Addition Operator - InfoPath Dev
in

InfoPath Dev

Jscript Addition Operator

Last post 06-30-2009 04:17 PM by phamj. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 06-29-2009 09:38 PM

    • phamj
    • Top 500 Contributor
      Female
    • Joined on 05-22-2008
    • Australia
    • Posts 26

    Jscript Addition Operator

    I'm trying to do something very simple - adding two numbers. However instead of "adding" it's concatenated instead.

    I have set my field to Whole Number (integer) and in my jscript code basically just add 1 

    function check_version() {

     var request_doc_version = XDocument.DOM.selectSingleNode("my:document/my:metadata/my:doc_version"); 
     var request_doc_create_version = XDocument.DOM.selectSingleNode("my:document/my:metadata/my:doc_create_version");

     var doc_version = getInfo( 'version' );
     
     if ( request_doc_create_version.text == "Yes") {
       
      request_doc_version = doc_version + 1;
      
     } else {
        
      request_doc_version.text = doc_version;
      
     }
     
     return;
     
    }

    Don't quite understand.

    Is there a way to conver the string to integer or number?

  • 06-29-2009 11:30 PM In reply to

    Re: Jscript Addition Operator

     Could you explain what the getInfo() function is doing?

     To convert a string to an int, you can use parseInt(var), but this line looks problematic:

    request_doc_version = doc_version + 1;

    because request_doc_version is an XML node, not a string variable. Try:

    request_doc_version.text = parseInt(doc_version) + 1;

    Jimmy Rishe / Software Developer / Microsoft MVP
    Qdabra Software
  • 06-30-2009 12:08 AM In reply to

    • phamj
    • Top 500 Contributor
      Female
    • Joined on 05-22-2008
    • Australia
    • Posts 26

    Re: Jscript Addition Operator

    Oh sorry it should have been request_doc_version.text initially - pasted the wrong code

     However none of them work. For example...

      XDocument.UI.Alert(request_doc_version.text + 1); // returns 21
      XDocument.UI.Alert(parseInt(request_doc_version.text) + 1); // returns 1.#QNAN
      XDocument.UI.Alert(parseFloat(request_doc_version.text) + 1); // returns 1.#QNAN

    Apparently you can do Convert.ToInt32 method in jscript... but I am not familar with this http://msdn.microsoft.com/en-us/library/system.convert.toint32(VS.71).aspx

    Any other ideas? Thanks

  • 06-30-2009 01:38 AM In reply to

    Re: Jscript Addition Operator

    Hi,

    What is the value of ‘request_doc_version.text' here? Can you check once?

    parseInt method works like this.

    parseInt("abc")     // Returns NaN.

    parseInt("12abc")   // Returns 12.

    parseInt("12") // Returns 12.

    Hope this helps.

    Rajitha
  • 06-30-2009 04:17 PM In reply to

    • phamj
    • Top 500 Contributor
      Female
    • Joined on 05-22-2008
    • Australia
    • Posts 26

    Re: Jscript Addition Operator

    I tried it again this morning it returned the right result from what I did previously. Strange.

     Thanks for the help.

    However that was just my quick fixed.

     But what I really want is a convert a string to a number as for doc_version, the value is actually taken from a database which returns a number as a string.

    I cannot use parseInt for this as it is a string and therefore returns 1.#NAN  

     

Page 1 of 1 (5 items)
Copyright © 2003-2019 Qdabra Software. All rights reserved.
View our Terms of Use.