what's the vbscript's cint() function in javascript

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • amy

    what's the vbscript's cint() function in javascript

    I have the following function to get the total qty:

    function calttl()
    {
    var ttlqty
    ttlqty=0
    for (i = 0; i <= document.qtymai n.orderdetail.l ength-1; i++)
    {
    ttlqty = ttlqty + document.qtymai n.qty.item(i).v alue
    }

    }

    The problem I have is the document.qtymai n.qty.item(i).v alue I get
    look like a string, so the number I get for ttlqty is not add up the
    number but concatenate.

    How do I convert the value I get to a number in javascript?

    Thanks for any help in advance.

    Amy
  • Lasse Reichstein Nielsen

    #2
    Re: what's the vbscript's cint() function in javascript

    ajiwu@elario.co m (amy) writes:
    [color=blue]
    > The problem I have is the document.qtymai n.qty.item(i).v alue I get
    > look like a string, so the number I get for ttlqty is not add up the
    > number but concatenate.[/color]

    <URL:http://jibbering.com/faq/#FAQ4_21>

    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    • Evertjan.

      #3
      Re: what's the vbscript's cint() function in javascript

      amy wrote on 16 okt 2003 in comp.lang.javas cript:
      [color=blue]
      > ttlqty = ttlqty + document.qtymai n.qty.item(i).v alue
      >[/color]

      document.qtymai n.qty.item[i].value

      I suspect.


      --
      Evertjan.
      The Netherlands.
      (Please change the x'es to dots in my emailaddress)

      Comment

      • Lasse Reichstein Nielsen

        #4
        Re: what's the vbscript's cint() function in javascript

        "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:
        [color=blue]
        > amy wrote on 16 okt 2003 in comp.lang.javas cript:
        >[color=green]
        > > ttlqty = ttlqty + document.qtymai n.qty.item(i).v alue
        > >[/color]
        >
        > document.qtymai n.qty.item[i].value
        >
        > I suspect.[/color]

        Probably not. It sounds like document.qtymai n.qty is a collection.
        These have a method called "item" (and some also have "namedItem" ).

        The equivalent notation would be
        document.qtymai n.qty[i].value

        I assume qtymain is a form and qty is the name of some elements in
        the form. The elements are probably checkboxes, since they have
        been given the same name.

        /L
        --
        Lasse Reichstein Nielsen - lrn@hotpop.com
        Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
        'Faith without judgement merely degrades the spirit divine.'

        Comment

        • Evertjan.

          #5
          Re: what's the vbscript's cint() function in javascript

          Lasse Reichstein Nielsen wrote on 16 okt 2003 in comp.lang.javas cript:[color=blue]
          > "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:[color=green]
          >> amy wrote on 16 okt 2003 in comp.lang.javas cript:[color=darkred]
          >> > ttlqty = ttlqty + document.qtymai n.qty.item(i).v alue[/color]
          >> document.qtymai n.qty.item[i].value
          >> I suspect.[/color]
          >
          > Probably not. It sounds like document.qtymai n.qty is a collection.
          > These have a method called "item" (and some also have "namedItem" ).
          >
          > The equivalent notation would be
          > document.qtymai n.qty[i].value
          >
          > I assume qtymain is a form and qty is the name of some elements in
          > the form. The elements are probably checkboxes, since they have
          > been given the same name.[/color]

          Would the qty[i] form be more tolerant of a stringed number, Lasse ?

          --
          Evertjan.
          The Netherlands.
          (Please change the x'es to dots in my emailaddress)

          Comment

          • amy J

            #6
            Re: what's the vbscript's cint() function in javascript



            yes, the qtymain is a form, qty is a collection of input box. I try to
            get all the value throught the loop, and get the total. The value I get
            is correct, just add up became concatenate.
            document.qtymai n.qty.item[i].value
            doesn't help. still doing concatename.

            *** Sent via Developersdex http://www.developersdex.com ***
            Don't just participate in USENET...get rewarded for it!

            Comment

            • Lasse Reichstein Nielsen

              #7
              Re: what's the vbscript's cint() function in javascript

              "Evertjan." <exjxw.hannivoo rt@interxnl.net > writes:
              [color=blue]
              > Would the qty[i] form be more tolerant of a stringed number, Lasse ?[/color]

              Probably not. I would expect square bracket notation and the "item"
              function to behave the same.

              The HTMLCollection interface is defined in the W3C DOM 2 HTML
              specification:
              <URL:http://www.w3.org/TR/DOM-Level-2-HTML/ecma-script-binding.html>
              In the ECMAScript bindings it says that using
              collection[1]
              is equivalent to
              collection.item (1)

              However, in ECMAScript, collection[1] is equivalent to
              collection["1"], since all property names are converted to strings
              before being looked up.

              Likewise, the "item" function might convert its argument to a number
              before using it. It doesn't have to, though. I can see that
              document.links. item("0x0")
              isn't the same as
              document.links. item("0")
              in Opera.


              /Lc
              --
              Lasse Reichstein Nielsen - lrn@hotpop.com
              Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
              'Faith without judgement merely degrades the spirit divine.'

              Comment

              • Evertjan.

                #8
                Re: what's the vbscript's cint() function in javascript

                amy J wrote on 16 okt 2003 in comp.lang.javas cript:
                [color=blue]
                > yes, the qtymain is a form, qty is a collection of input box. I try to
                > get all the value throught the loop, and get the total. The value I get
                > is correct, just add up became concatenate.
                > document.qtymai n.qty.item[i].value
                > doesn't help. still doing concatename.[/color]


                <script>

                // You can prevent a concatenation by

                alert(1*"11"+1* "7") //this will give 18

                // or

                alert(+"11"+ +"7") //this will also give 18

                //while

                alert("11"+"7") //this will give 117


                </script>

                --
                Evertjan.
                The Netherlands.
                (Please change the x'es to dots in my emailaddress)

                Comment

                • amy J

                  #9
                  Re: what's the vbscript's cint() function in javascript



                  Evertjan, thanks for the correct answer.

                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  Working...