|
-
Jul 29th, 2002, 07:05 AM
#1
Thread Starter
Fanatic Member
data types in javascript (resolved)
i've got a couple of questions regarding data types in javascript:
1. i have a variable that i've declared as "var iOrders;", that's meant to hold an integer. i'm trying to increment this everytime a function is called, using "iOrders += 1;", and then in another function i want a loop that loops through the amount held in iOrders, using this:
Code:
for (i = iOrders; i > 0; i--) {
//do stuff
}
but it's saying that the value of iOrders is NaN. is there something i'm meant to do to define iOrders as an integer?
2. i have a multidimensional array which holds some product information, one of the columns being a number (although it's in a string (ie. arrProducts[1][3] = "1234"; ), because some other columns are strings. i need to compare the value of that to a number entered in a textbox, so how can i convert them both to integers? at the moment i'm using this:
Code:
if (document.form1.text1.value > arrProducts[i][3]) {
//do stuff
}
thanks for any help
Last edited by tr0n; Jul 31st, 2002 at 08:19 AM.
-
Jul 29th, 2002, 07:54 AM
#2
Hyperactive Member
1) try setting iOrders to 0 (var iOrders=0 before the for loop !
2) You'll need to post more code up so I can see what you're trying to do ! There may be a problem with the way you are defining your MD Array
-
Jul 29th, 2002, 08:41 AM
#3
Thread Starter
Fanatic Member
thanks for the first question 
right, well this is how i'm defining the MD array:
Code:
for (i = 0; i < 500; i++) {
arrProducts[i] = new Array();
}
and then i assign values like this:
Code:
arrProducts[i][0] = "BLAH-00"; //text
arrProducts[i][1] = "A Product"; //text
arrProducts[i][2] = "10"; //number
arrProducts[i][3] = "100"; //number
then in a function i need to test if a value entered in a textbox is great than arrProducts[i][2]. currently doing it like this:
Code:
if (document.form1.text1.value > arrProducts[i][2]) {
//do stuff
}
but that's just obviously comparing two text values.
-
Jul 29th, 2002, 08:46 AM
#4
Hyperactive Member
try Math.round()
eg:
Code:
if (Math.round(document.form1.text1.value) > Math.round(arrProducts[i][2])) {
//do stuff
}
-
Jul 29th, 2002, 10:48 AM
#5
Thread Starter
Fanatic Member
ah, yeah, that seems to work. thanks.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|