469,361 Members | 2,453 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

adding values to an array

347 100+
I am trying to write an array that adda a number to the array on the click of a button, this is so i can send a series of numbers to a second page.

im just not sure how to do it???

never used arrays
Jan 22 '09 #1
11 1502
Dormilich
8,652 Expert Mod 8TB
I'm not aware that an array can write something to another array..... you probably mean function. you can use an array method (Array MDC), e.g.
Expand|Select|Wrap|Line Numbers
  1. your_array.push(new_value);
regards
Jan 22 '09 #2
colinod
347 100+
what i need is the array to contain a series of numbers

i.e 123,234,345 etc

will the push function do this?

The idea is that the array holds the id for things on our site so you can click them as a favorite and then view all favorites from another page....a bit like a shopping cart
Jan 22 '09 #3
Dormilich
8,652 Expert Mod 8TB
let me explain the push() method:
Expand|Select|Wrap|Line Numbers
  1. var my_array = [1,2];
  2. // my_array now contains 1,2
  3. alert(my_array.length); // 2
  4. my_array.push(3);
  5. // my_array now contains 1,2,3
  6. alert(my_array.length); // 3
note: you know that numbers are not allowed for IDs?

regards
Jan 22 '09 #4
colinod
347 100+
So i could do something like this

Expand|Select|Wrap|Line Numbers
  1. var my_array = []; 
  2. // my_array now contains nothing 
  3. my_array.push(123); 
  4. // my_array now contains 123
  5.  
then if i wanted to add another number
Expand|Select|Wrap|Line Numbers
  1. my_array.push(456); 
  2. // my_array now contains 123,456
  3.  
Is this correct???

Also would you know how to get the amount stored in the array item from an asp variable

eg the 123 or 456 to come from asp ID
Jan 22 '09 #5
Dormilich
8,652 Expert Mod 8TB
@colinod
yes

@colinod
sorry, I can't help with ASP, you should ask in the ASP forum for help
Jan 22 '09 #6
colinod
347 100+
thankyou for your help
Jan 22 '09 #7
Dormilich
8,652 Expert Mod 8TB
I'm glad I could help.
Jan 22 '09 #8
colinod
347 100+
I have got the array being populated with an asp variable but how can i get the page to display the content of my_array, i have tried

Expand|Select|Wrap|Line Numbers
  1.  
  2. <script language="javascript"> 
  3. document.write(my_array); 
  4. </script>
  5.  
in the body of the page but get nothing displayed
Jan 23 '09 #9
Dormilich
8,652 Expert Mod 8TB
you could try the Array.toString() or Array.toSource() method (see toString MDC)
Jan 23 '09 #10
colinod
347 100+
I dont think thats quite what im looking for, i need a way of taking each entry into the array and having it appear in the html on my page, its just so i can see if the array is holding all the information
Jan 23 '09 #11
Dormilich
8,652 Expert Mod 8TB
well, that's what the functions do, show you the content (i.e. returning the content)
Jan 23 '09 #12

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

7 posts views Thread by David | last post: by
1 post views Thread by HolaGoogle | last post: by
5 posts views Thread by Troy | last post: by
17 posts views Thread by Sri | last post: by
3 posts views Thread by Brian Piotrowski | last post: by
14 posts views Thread by Paul_Madden via DotNetMonster.com | last post: by
1 post views Thread by mtchatchez | last post: by
11 posts views Thread by dennis.sprengers | last post: by
2 posts views Thread by AndyW2387 | last post: by
reply views Thread by zhoujie | last post: by
reply views Thread by suresh191 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.