473,480 Members | 1,807 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

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 19159
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
3432
by: Frank | last post by:
When I used IE 6.0 to view the ASP page on Window 2000 server PC, I encountered the error message: "Expected end of statement". The ASP page code is as:...
3
13219
by: Rahul Bakshi | last post by:
Hi I am getting this error which is frustrating me a lot Microsoft VBScript runtime error '800a01c9' This key is already associated with an element of this collection /process.asp, line...
12
6461
by: MFA | last post by:
Hi All Thanks to all who replied to my question dated 16/10/2003 with the same subject.. In all replies I got every one is saying that I am using cint() etc. But i am not using any convert...
29
5983
by: Christopher Brandsdal | last post by:
If I have a .ASP page that runs JScript code - is it possible to include an ..ASP page that runs VBscript???
20
5943
by: Harag | last post by:
Hi All. I'm stating out doing some web developing. I was wondering which of the server side languages should I concentrate on and learn. I Know CSS, HTML, T-SQL I can look at the client...
3
6024
by: pjglick | last post by:
I am sorry if this sounds hokey but I am a newbie to ASP. I have a VBScript running in an ASP page. The script makes a connection to Oracle via and ADODB connection. When my clients connect...
2
2854
by: Beemer Biker | last post by:
I put together a few lines of vbscript so I could dump the contents of a string to my C drive. It worked fine in a small test.htm where I put the vbscript at the top of the file. It failed to...
10
7985
by: jasone | last post by:
hi everyone! any advice given will be MUCH appreciated, i have spent about 10 hours on this bit of script... a rating system. I am having realt trouble overcoming this problem at runtime ...
2
2768
by: mdock | last post by:
Hello, I have a javascript grid on my ASP page which displays information about the history of specific units produced in our manufacturing facility. One of the results is the order number on...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
1
6744
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
6981
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
5348
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.