473,320 Members | 1,846 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.

sending array to function parameter

32
I know its possible, but I haven't been able to get a hold of how to send the parameter as an array or string?

Expand|Select|Wrap|Line Numbers
  1. function updateHours(el, val)
  2. {
  3.      if(el!=null && val!=null)
  4.      {
  5.           var element = document.getElementById(el);
  6.           element.innerHTML = element.value + val;
  7.      }
  8. }
  9.  
is what I have right now and it will work as long as the element is a single string.
to make this robust, I want to be able to insert an array into both parameters or just 1 parameter... so it would update accordingly

Expand|Select|Wrap|Line Numbers
  1. function updateHours("['el1','el2','el3']", "['val1','val2','val3']")
  2. {
  3. }
  4.  
would update 3 elements taking into account the appropriate 3 values and

Expand|Select|Wrap|Line Numbers
  1. function updateHours("['el1','el2','el3']", "val")
  2. {
  3. }
  4.  
would update all 3 elements taking into account only 1 value.


Expand|Select|Wrap|Line Numbers
  1. function updateHours("el", "['val1','val2','val3']")
  2. {
  3. }
  4.  
would update 1 element with an assortment of values
Jan 8 '08 #1
1 2146
acoder
16,027 Expert Mod 8TB
Pass the array as ['el1','el2','el3'] and use a for loop to loop over the elements, e.g.
Expand|Select|Wrap|Line Numbers
  1. for (i=0; i<el.length; i++) {
  2.      var element = document.getElementById(el[i]);
  3.      element.value = element.value + val;
  4. }
Jan 9 '08 #2

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

Similar topics

5
by: wilson | last post by:
Dear all, In this time, I want to pass array to function. What should I declare the parameter in the function?i int array or int array? Which one is correct? ...
11
by: truckaxle | last post by:
I am trying to pass a slice from a larger 2-dimensional array to a function that will work on a smaller region of the array space. The code below is a distillation of what I am trying to...
8
by: Michel Rouzic | last post by:
I had a program that worked perfectly, and that read .wav files. I changed something so the tags of the wave file, instead of being each in a different variable, are all in an array, called tag. i...
1
by: pini_soos | last post by:
Hi there, i writing a c# application which call to a com object written in vb. the function in this object which i call gets as parameter: a variant array and a variant dsnstring. i tried to cast...
2
by: Tobias Olbort | last post by:
Hello, i've a outer function, which takes a params-array as a parameter. I want to pass this array to inner function with a params-array (e. g. string.format). When i've passed an integer to...
8
by: intrepid_dw | last post by:
Hello, all. I've created a C# dll that contains, among other things, two functions dealing with byte arrays. The first is a function that returns a byte array, and the other is intended to...
7
by: Jim Carlock | last post by:
Looking for suggestions on how to handle bad words that might get passed in through $_GET variables. My first thoughts included using str_replace() to strip out such content, but then one ends...
5
by: nescio | last post by:
hello, i have made an application in php so that people can make, on the fly, a form. when they submit the form there is a javascript formvalidation. because we do not know how many fields...
26
by: aruna.mysore | last post by:
Hi all, I have a specific problem passing a function pointer array as a parameter to a function. I am trying to use a function which takes a function pointer array as an argument. I am too sure...
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: 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
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
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.