473,324 Members | 2,313 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,324 software developers and data experts.

setup an dynamic array

Hi!

I'm all new into js so I'm kind of stuck with this script of mine.
I need it to fetch the choosen value in a dropdown menu when the user clicks an "Add" button. The value should then be stored somehow, so that the next time he clicks the same "Add" button, but maybe chooses another value from the drop-down, the script stores this value and so on. I've been thinking of doing it through an dynamic array, but I'm all stuck....Here's what I got so far..

Expand|Select|Wrap|Line Numbers
  1. <script>
  2. function addMailAddressses(){
  3.    var email = document.form.Mail.value
  4.    agree = confirm('Is the choosen e-mailaddress correct: ' + email )
  5.    if (agree){
  6.          alert('The address, ' + email + ' , has been added.')
  7.        var emails = newArray(9);
  8.     var i;
  9.  for (i = 1; i < 10; i++) {
  10. emails[i] = email + ';';
  11.  
  12.  
  13. }
  14.    else {
  15.    return false
  16.    }
  17. }
  18. </script> 
Jan 19 '08 #1
3 2379
acoder
16,027 Expert Mod 8TB
Declare the array as
Expand|Select|Wrap|Line Numbers
  1. var emails = [];
and then just add as required:
Expand|Select|Wrap|Line Numbers
  1. emails[0] = someEmail;
Jan 21 '08 #2
Thank you for your answer.

Is it correct to let the for-loop increase the array-index for me?

Have I done the code correctly or should I do it any differently?

The code should add one e-mailaddress to the array every time he puts in an address to the input-box and clicks the submit-button.

Eventually the whole array should be put into my DB.
Jan 21 '08 #3
acoder
16,027 Expert Mod 8TB
Is it correct to let the for-loop increase the array-index for me?

Have I done the code correctly or should I do it any differently?

The code should add one e-mailaddress to the array every time he puts in an address to the input-box and clicks the submit-button.

Eventually the whole array should be put into my DB.
If you're only adding one address each time, the declaration of the array should be outside the function.

There's no need for a for loop because you're only adding one email address each time. You can use the length of the array to dynamically add a new item or use the array's push() method.

For storage in the database, you will need a server-side language.
Jan 22 '08 #4

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

Similar topics

6
by: Vasileios Zografos | last post by:
Hello, I have a function that generates some values (e.g. vertices in 2d space) the number of which I dont know. So, it could generate 20 vertices, 100 vertices, or even 1 vertex. void...
5
by: meyousikmann | last post by:
I am having a little trouble with dynamic memory allocation. I am trying to read a text file and put the contents into a dynamic array. I know I can use vectors to make this easier, but it has to...
6
by: Materialised | last post by:
Hi Everyone, I apologise if this is covered in the FAQ, I did look, but nothing actually stood out to me as being relative to my subject. I want to create a 2 dimensional array, a 'array of...
11
by: C C++ C++ | last post by:
Hi all, got this interview question please respond. How can you quickly find the number of elements stored in a a) static array b) dynamic array ? Rgrds MA
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
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
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

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.