473,320 Members | 2,162 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

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 1730
Dormilich
8,658 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,658 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,658 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,658 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,658 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,658 Expert Mod 8TB
well, that's what the functions do, show you the content (i.e. returning the content)
Jan 23 '09 #12

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

Similar topics

7
by: David | last post by:
I have an array that contains numbers in string elements , i want to convert this to integers, i have made a for loop that uses the number of elements in the array and then adds 0, thereby...
1
by: HolaGoogle | last post by:
Hi all, Please help me with the following..it's realy urgent and i tried everything i could and i can't get it work properly!! Thanks in advance. Here's what i'm trying to accomplish: in my...
5
by: Troy | last post by:
Hello, I have a dumb question. I have two array objects of type double with 12 elements in each object. I'd like to add the two objects but dont know how to. Any ideas? thanks
17
by: Sri | last post by:
How do you add an n-bit number in C? Regards, Sri
3
by: Brian Piotrowski | last post by:
Hi All, I've probably done this before, but for the life of me I can't remember how I did it. I need to move values from a DB table into an array to be used for other queries. The number of...
14
by: Paul_Madden via DotNetMonster.com | last post by:
Basically I have a listbox to which I add simple STRING items- I have a progress bar which I increment whenever I populate another portion of the complete set of items I wish to add. What I observe...
5
by: Chris Lieb | last post by:
I am trying to add an event listener to the keyup event for some text inputs that I am creating dynamically. I have no problems getting it to work in Firefox, but IE just ignores them. I have...
1
by: mtchatchez | last post by:
I have several 2-dimensional arrays which I want to sum the values of, returning an array that has for each of its values the sum from all the others (if that makes sense?) ... Okay ... maybe an...
11
by: dennis.sprengers | last post by:
Consider the following multi-dimensional array: --------------------------- $arr = array( array(3, 5, 7, 9), array(2, 4, 6, 8), array(1, 3, 5, 7) ); function add_arrays($arr) { for ($row =...
2
by: AndyW2387 | last post by:
Hi I'm quite a newbie and have been struggling with sessions (!) What I'm trying to do is to add submitted values from a textfield (or ID number) to an array which is in a $_SESSION. ( It's for a...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

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.