473,394 Members | 1,971 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,394 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 1733
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: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
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...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
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...

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.