469,352 Members | 2,107 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,352 developers. It's quick & easy.

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

amy
I have the following function to get the total qty:

function calttl()
{
var ttlqty
ttlqty=0
for (i = 0; i <= document.qtymain.orderdetail.length-1; i++)
{
ttlqty = ttlqty + document.qtymain.qty.item(i).value
}

}

The problem I have is the document.qtymain.qty.item(i).value 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
Jul 20 '05 #1
8 18933
aj***@elario.com (amy) writes:
The problem I have is the document.qtymain.qty.item(i).value I get
look like a string, so the number I get for ttlqty is not add up the
number but concatenate.


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

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #2
amy wrote on 16 okt 2003 in comp.lang.javascript:
ttlqty = ttlqty + document.qtymain.qty.item(i).value


document.qtymain.qty.item[i].value

I suspect.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #3
"Evertjan." <ex**************@interxnl.net> writes:
amy wrote on 16 okt 2003 in comp.lang.javascript:
ttlqty = ttlqty + document.qtymain.qty.item(i).value


document.qtymain.qty.item[i].value

I suspect.


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

The equivalent notation would be
document.qtymain.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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Lasse Reichstein Nielsen wrote on 16 okt 2003 in comp.lang.javascript:
"Evertjan." <ex**************@interxnl.net> writes:
amy wrote on 16 okt 2003 in comp.lang.javascript:
> ttlqty = ttlqty + document.qtymain.qty.item(i).value

document.qtymain.qty.item[i].value
I suspect.


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

The equivalent notation would be
document.qtymain.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.


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)
Jul 20 '05 #5


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.qtymain.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!
Jul 20 '05 #6
"Evertjan." <ex**************@interxnl.net> writes:
Would the qty[i] form be more tolerant of a stringed number, Lasse ?


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 - lr*@hotpop.com
Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #7
amy J wrote on 16 okt 2003 in comp.lang.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.qtymain.qty.item[i].value
doesn't help. still doing concatename.

<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)
Jul 20 '05 #8


Evertjan, thanks for the correct answer.

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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

29 posts views Thread by Christopher Brandsdal | last post: by
20 posts views Thread by Harag | last post: by
3 posts views Thread by pjglick | last post: by
2 posts views Thread by Beemer Biker | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.